package nsq
|
|
import (
|
"apsClient/conf"
|
"apsClient/pkg/logx"
|
"apsClient/pkg/nsqclient"
|
)
|
|
var producer nsqclient.Producer
|
|
func GetProducer() nsqclient.Producer {
|
return producer
|
}
|
|
func initProducer() (err error) {
|
producer, err = nsqclient.NewProducer(conf.Conf.NsqConf.NsqdAddr)
|
if err != nil {
|
logx.Errorf("NewProducer err:%v", err)
|
return err
|
}
|
// 测试发布数据
|
//go func() {
|
// for {
|
// time.Sleep(time.Second)
|
// _ = producer.Publish("test", []byte("123"))
|
// }
|
//}()
|
|
//go func() {
|
// for {
|
// time.Sleep(time.Second * 2)
|
// err := producer.Publish("aps.wangpengfei.erp.cstReply", []byte("456"))
|
// logx.Infof("=====err:%v", err)
|
// }
|
//}()
|
|
//go func() {
|
// for {
|
// time.Sleep(time.Second * 5)
|
// applyMaterial := ApplyOrderMaterial{
|
// FBillNo: "123",
|
// FNumber: "456",
|
// UseAmount: 1,
|
// }
|
//
|
// applyBytes, err := json.Marshal([]*ApplyOrderMaterial{&applyMaterial})
|
// if err != nil {
|
// return
|
// }
|
//
|
// producer := GetProducer()
|
// err = producer.Publish(fmt.Sprintf("aps.%v.erp.cstApply", conf.WebConf.NodeId), applyBytes)
|
// logx.Infof("===============ApplyMaterialByProduct topic:%v, applyBytes:%v, err:%v", fmt.Sprintf("aps.%v.erp.cstApply", conf.WebConf.NodeId), string(applyBytes), err)
|
// if err != nil {
|
// return
|
// }
|
// }
|
//}()
|
return nil
|
}
|