Documentation
¶
Overview ¶
Package kafkat provides test helpers for Kafka operations using the franz-go client. It creates isolated topics for each test and automatically cleans them up after the test completes.
Index ¶
- type Kafka
- func (k *Kafka) Address() string
- func (k *Kafka) ConsumerConfig(topic, groupId string) kafkax.ConsumerConfig
- func (k *Kafka) CreateDefaultTopic(topic string)
- func (k *Kafka) PublisherConfig(topic string) kafkax.PublisherConfig
- func (k *Kafka) ReadMessage(topic string, offset int64) *kgo.Record
- func (k *Kafka) WriteMessages(msgs ...*kgo.Record)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Kafka ¶
type Kafka struct {
// contains filtered or unexported fields
}
Kafka provides a test helper for Kafka operations. It manages Kafka client connections and automatically cleans up created topics after each test.
func NewKafka ¶
NewKafka creates a new Kafka test client. Connection parameters can be overridden using environment variables: KAFKA_ADDRESS, KAFKA_USERNAME, KAFKA_PASSWORD.
func (*Kafka) ConsumerConfig ¶
func (k *Kafka) ConsumerConfig(topic, groupId string) kafkax.ConsumerConfig
ConsumerConfig returns a ConsumerConfig for the specified topic and consumer group, pre-configured with the Kafka connection details.
func (*Kafka) CreateDefaultTopic ¶
CreateDefaultTopic creates a new topic with a single partition. The topic is automatically deleted when the test completes. Panics if topic creation fails.
func (*Kafka) PublisherConfig ¶
func (k *Kafka) PublisherConfig(topic string) kafkax.PublisherConfig
PublisherConfig returns a PublisherConfig for the specified topic, pre-configured with the Kafka connection details.
func (*Kafka) ReadMessage ¶
ReadMessage retrieves a single message from the specified topic at the given offset. Panics if the message cannot be read.
func (*Kafka) WriteMessages ¶
WriteMessages publishes one or more messages to their respective topics. Panics if any message fails to produce.