sarama.go
699 字节
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"
)
func Run() {
messageHandlerMap := make(map[string]func(message *sarama.ConsumerMessage) error)
messageHandlerMap["demo-v1"] = Demo
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
}