数据上报
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.
 
 

27 lines
655 B

package _kafka
import (
"log"
)
type KafkaHelper struct {
Brokers []string
GroupId string
client *ConsumerGroupHandler
}
func (the *KafkaHelper) initialClient() *ConsumerGroupHandler {
the.client = NewConsumerGroupHandler(the.Brokers, the.GroupId)
return the.client
}
func (the *KafkaHelper) Initial() *ConsumerGroupHandler {
return the.initialClient()
}
func (the *KafkaHelper) Subscribe(topic string, callback func(topic string, msg string) bool) {
log.Printf("=================开始订阅 %s [%s]=================", the.Brokers, topic)
the.client.Subscribe(topic, callback)
}
func (the *KafkaHelper) Worker() {
go the.client.Worker()
}