sarama.go
900 字节
package consumer
import (
"github.com/Shopify/sarama"
saramaConsumer "github.com/linmadan/egglib-go/mom/kafka/sarama"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer/handle"
)
func Run() {
messageHandlerMap := make(map[string]func(message *sarama.ConsumerMessage) error)
messageHandlerMap["demo-v1"] = Demo
//"指定topic" => 对应的处理方法
messageHandlerMap[constant.KAFKA_BUSINESS_TOPIC] = handle.SyncDataBusinessAdmin
err := saramaConsumer.StartConsume(constant.KAFKA_HOSTS, constant.SERVICE_NAME, messageHandlerMap, log.Logger)
log.Logger.Error(err.Error())
}
func Demo(message *sarama.ConsumerMessage) error {
k := string(message.Key)
v := string(message.Value)
log.Logger.Debug("message===>" + k + ":" + v)
return nil
}