Documentation
¶
Overview ¶
Package kafka 提供 Kafka 消息队列集成(对标 Spring Kafka 的 KafkaTemplate): 生产/消费封装 + 原生客户端暴露。基于纯 Go 的 segmentio/kafka-go。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetConsumer ¶ added in v1.36.0
func SetConsumer(consumer *Consumer)
SetConsumer 设置全局消费者(装配后调用)。
func SetProducer ¶ added in v1.36.0
func SetProducer(producer *Producer)
SetProducer 设置全局生产者(装配后调用)。
Types ¶
type Config ¶
type Config struct {
// Brokers 节点列表(如 127.0.0.1:9092)。
Brokers []string
// Topic 默认主题(可空,操作时显式指定)。
Topic string
// GroupID 消费组(Consumer 使用)。
GroupID string
// Timeout 网络超时(默认 10s)。
Timeout time.Duration
}
Config Kafka 客户端配置。
type Consumer ¶
type Consumer struct {
// contains filtered or unexported fields
}
Consumer 消费端(对标 @KafkaListener)。
func NewConsumer ¶
NewConsumer 创建消费者(同一消费组内分区均衡)。
type Message ¶
type Message struct {
Topic string
Key string
Value []byte
Partition int
Offset int64
Time time.Time
Headers map[string]string
}
Message 消费消息。
Click to show internal directories.
Click to hide internal directories.