Your ROOT_URL in app.ini is http://git.slaventius.ru/ but you are visiting http://37.143.12.169/test3k/authPostman/blame/commit/cf63ef7f811a18a55032924191070e01ed2f62c8/internal/transport/kafka/reader.go You should set ROOT_URL correctly, otherwise the web may not work correctly.

46 lines
927 B

2 years ago
package kafka
import (
"context"
"fmt"
"time"
2 years ago
"git.slaventius.ru/test3k/authPostman/internal/config"
2 years ago
2 years ago
"github.com/segmentio/kafka-go"
)
type KafkaReader struct {
ctx context.Context
config *config.Config
reader *kafka.Reader
first string
topic string
}
func NewReader(ctx context.Context, config *config.Config, topic string, address ...string) *KafkaReader {
return &KafkaReader{
ctx: ctx,
config: config,
reader: kafka.NewReader(kafka.ReaderConfig{
Topic: topic,
Brokers: address,
GroupID: fmt.Sprintf("consumer-group-%s", topic),
// Partition: 0, // TODO
MinBytes: 10e3, // 10KB
MaxBytes: 10e6, // 10MB
ReadBackoffMax: time.Millisecond * 100,
}),
first: address[0],
topic: topic,
}
}
func (s *KafkaReader) Close() error {
return s.reader.Close()
}
2 years ago
func (s *KafkaReader) ReadMessage() (kafka.Message, error) {
2 years ago
return s.reader.ReadMessage(s.ctx)
}