Initial commit
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package server
|
||||
|
||||
// import (
|
||||
// "context"
|
||||
// "fmt"
|
||||
// "stat/common/kafka"
|
||||
// "stat/service/consumer"
|
||||
// "stat/statg"
|
||||
|
||||
// "github.com/Shopify/sarama"
|
||||
// )
|
||||
|
||||
// var topicList = []string{
|
||||
// "user_access",
|
||||
// "user_register",
|
||||
// "user_recharge",
|
||||
// "user_withdraw",
|
||||
// }
|
||||
|
||||
// type consumerGroupHandler struct{}
|
||||
|
||||
// func (consumerGroupHandler) Setup(_ sarama.ConsumerGroupSession) error { return nil }
|
||||
// func (consumerGroupHandler) Cleanup(_ sarama.ConsumerGroupSession) error { return nil }
|
||||
// func (h consumerGroupHandler) ConsumeClaim(sess sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error {
|
||||
// for msg := range claim.Messages() {
|
||||
|
||||
// // 消息处理
|
||||
// switch msg.Topic {
|
||||
// case "user_access":
|
||||
// consumer.UserAccessHandler(msg)
|
||||
// case "user_register":
|
||||
// consumer.UserRegisterHandler(msg)
|
||||
// case "user_recharge":
|
||||
// consumer.UserReChargeHandler(msg)
|
||||
// case "user_withdraw":
|
||||
// consumer.UserWithdrawOrder(msg)
|
||||
// }
|
||||
|
||||
// // 标记该消息已处理
|
||||
// sess.MarkMessage(msg, "")
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// func runConsumer() {
|
||||
// group := kafka.InitKafkaConsumerGroup([]string{statg.Conf.Kafka.Url}, statg.Conf.Kafka.Group)
|
||||
// defer func() { _ = group.Close() }()
|
||||
|
||||
// // Track errors
|
||||
// go func() {
|
||||
// for err := range group.Errors() {
|
||||
// fmt.Println("ERROR", err)
|
||||
// }
|
||||
// }()
|
||||
|
||||
// // Iterate over consumer sessions.
|
||||
// ctx := context.Background()
|
||||
// for {
|
||||
// handler := consumerGroupHandler{}
|
||||
|
||||
// // `Consume` should be called inside an infinite loop, when a
|
||||
// // server-side rebalance happens, the consumer session will need to be
|
||||
// // recreated to get the new claims
|
||||
// err := group.Consume(ctx, topicList, handler)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user