kafka

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2021 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

kafka-do

v0.3.0

kafka-do

Go Reference

What

Higher level abstraction for franz-go.

Why

We want to be able to write our kafka applications without making the same things over and over.

Batch Consume
Consume messages as much as you defined.

Batch Produce
Produce messages as a batch to a topic.

Example

For e2e example, check here.

	producer, err := kafka.NewProducer("127.0.0.1:9092")
	if err != nil {
		log.Fatal(err)
	}
	defer producer.Close()

	producer.Produce(context.Background(), []kafka.Message{
		kafka.Message("message 1"),
		kafka.Message("message 2"),
		kafka.Message("message 3"),
		kafka.Message("message 4"),
	}, "messages")

	consumer, err := kafka.NewConsumer("kafka_do", []string{"messages"}, []string{"127.0.0.1:9092"})
	if err != nil {
		log.Fatal(err)
	}
	defer consumer.Close()

	messages, errs := consumer.ConsumeBatch(context.Background(), 2)
	for _, message := range messages {
		log.Println(message)
	}

	for _, err := range errs {
		log.Println(err)
	}

Development

To run tests, start a kafka that runs on ":9092".

go test ./... -v -cover -count=1 -race

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer added in v0.3.0

type Consumer struct {
	// contains filtered or unexported fields
}

func NewConsumer added in v0.3.0

func NewConsumer(groupName string, topics []string, brokers []string) (*Consumer, error)

func (*Consumer) Close added in v0.3.0

func (c *Consumer) Close()

func (*Consumer) ConsumeBatch added in v0.3.0

func (c *Consumer) ConsumeBatch(ctx context.Context, batchSize int) ([]Message, []kgo.FetchError)

type Message added in v0.3.0

type Message []byte

type Producer added in v0.3.0

type Producer struct {
	// contains filtered or unexported fields
}

func NewProducer

func NewProducer(brokers ...string) (*Producer, error)

func (*Producer) Close added in v0.3.0

func (p *Producer) Close()

func (*Producer) Produce added in v0.3.0

func (p *Producer) Produce(ctx context.Context, messages []Message, topic string) kgo.ProduceResults

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL