Queue Streamer is a Go package that processes and transfers data between Kafka topics with exactly-once delivery guarantees. This package receives messages from Kafka brokers and transfers them to specified topics. This document explains how to install and use Queue Streamer.
To install Queue Streamer, use the Go modules:
go get github.com/violetpay-org/queue-streamer
Here is an example code to use Queue Streamer.
package main
import (
"github.com/violetpay-org/queue-streamer"
"sync"
)
func main() {
wg := &sync.WaitGroup{}
brokers := []string{"localhost:9092"}
// Topic name and partition
origin := qstreamer.Topic("origin-topic", 3)
// Create a topic streamer from the brokers and the origin topic.
streamer := qstreamer.NewTopicStreamer(brokers, origin)
// Serializer that converts the message to the message to be produced.
// In this case, the message is not converted, so it is a pass-through serializer.
serializer := qstreamer.NewPassThroughSerializer()
// Destination topic and partition
destination1 := qstreamer.Topic("destination-topic-1", 5)
cfg := qstreamer.NewStreamConfig(serializer, destination1)
streamer.AddConfig(cfg)
go streamer.Run()
defer streamer.Stop()
wg.Add(1)
wg.Wait()
}
-
Set Topics: Use the
Topic()
to set the start and end topics. -
Create Streamer: Create a new streamer with the
NewTopicStreamer()
function. This function takes the Kafka brokers and the origin topic as arguments. -
Set Serializer: Create a new serializer with the
NewPassThroughSerializer()
function. This function is used to convert the message to the message to be produced. In this case, the message is not converted, so it is a pass-through serializer. -
Set Destination Topic: Use the
Topic()
to set the destination topic and partition. -
Set Configuration: Create a new configuration with the
NewStreamConfig()
function. This function takes the serializer and the destination topic as arguments. Add the configuration to the streamer with theAddConfig()
function. -
Run Streamer: Run the streamer with the
Run()
function. This function starts the streamer and processes the messages.
Contributions are welcome! You can contribute to the project by reporting bugs, requesting features, and submitting pull requests.
Queue Streamer is distributed under the MIT License. See the LICENSE file for more details.