You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
754 B
38 lines
754 B
package kafka
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/segmentio/kafka-go"
|
|
)
|
|
|
|
type KafkaReader struct {
|
|
ctx context.Context
|
|
reader *kafka.Reader
|
|
first string
|
|
topic string
|
|
}
|
|
|
|
func NewReader(ctx context.Context, topic string, address ...string) *KafkaReader {
|
|
return &KafkaReader{
|
|
ctx: ctx,
|
|
reader: kafka.NewReader(kafka.ReaderConfig{
|
|
Topic: topic,
|
|
Brokers: address,
|
|
GroupID: "consumer-group-id", // TODO
|
|
Partition: 0, // TODO
|
|
MinBytes: 10e3, // 10KB
|
|
MaxBytes: 10e6, // 10MB
|
|
}),
|
|
first: address[0],
|
|
topic: topic,
|
|
}
|
|
}
|
|
|
|
func (s *KafkaReader) Close() error {
|
|
return s.reader.Close()
|
|
}
|
|
|
|
func (s *KafkaReader) ReadMessage(key string, value string) error {
|
|
return nil
|
|
}
|
|
|