审查视图

pkg/port/consumer/produce/produce.go 1.7 KB
唐旭辉 authored
1 2
package produce
唐旭辉 authored
3 4 5 6
// import (
// 	"fmt"
// 	"strconv"
// 	"time"
唐旭辉 authored
7
唐旭辉 authored
8
// 	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/consumer/configs"
唐旭辉 authored
9
唐旭辉 authored
10 11 12
// 	"github.com/Shopify/sarama"
// 	"github.com/astaxie/beego/logs"
// )
唐旭辉 authored
13
唐旭辉 authored
14 15 16
// var (
// 	producer sarama.SyncProducer
// )
唐旭辉 authored
17
唐旭辉 authored
18
// func init() {
唐旭辉 authored
19
唐旭辉 authored
20 21 22 23 24 25 26 27 28 29
// 	logs.Info("init kafka producer, it may take a few seconds to init the connection\n")
// 	var err error
// 	mqConfig := sarama.NewConfig()
// 	mqConfig.Producer.Return.Successes = true
// 	mqConfig.Version = sarama.V0_10_2_1
// 	if err = mqConfig.Validate(); err != nil {
// 		msg := fmt.Sprintf("Kafka producer config invalidate. config: %v. err: %v", configs.Cfg, err)
// 		logs.Info(msg)
// 		panic(msg)
// 	}
唐旭辉 authored
30
唐旭辉 authored
31 32 33 34 35 36
// 	producer, err = sarama.NewSyncProducer(configs.Cfg.Servers, mqConfig)
// 	if err != nil {
// 		msg := fmt.Sprintf("Kafak producer create fail. err: %v", err)
// 		logs.Info(msg)
// 		panic(msg)
// 	}
唐旭辉 authored
37
唐旭辉 authored
38
// }
唐旭辉 authored
39
唐旭辉 authored
40 41 42 43 44 45 46
// func produce(topic string, key string, content string) error {
// 	msg := &sarama.ProducerMessage{
// 		Topic:     topic,
// 		Key:       sarama.StringEncoder(key),
// 		Value:     sarama.StringEncoder(content),
// 		Timestamp: time.Now(),
// 	}
唐旭辉 authored
47
唐旭辉 authored
48 49 50 51 52 53 54 55 56
// 	_, _, err := producer.SendMessage(msg)
// 	if err != nil {
// 		msg := fmt.Sprintf("Send Error topic: %v. key: %v. content: %v", topic, key, content)
// 		logs.Info(msg)
// 		return err
// 	}
// 	logs.Info("Send OK topic:%s key:%s value:%s\n", topic, key, content)
// 	return nil
// }
唐旭辉 authored
57
唐旭辉 authored
58 59 60 61 62 63 64 65 66 67
// func Producer() error {
// 	key := strconv.FormatInt(time.Now().UTC().UnixNano(), 10)
// 	value := "this is a new kafka message!"
// 	err := produce("topic_test", key, value)
// 	if err != nil {
// 		logs.Info("producer err:%s \n", err)
// 		return err
// 	}
// 	return nil
// }