fix
zhangqian
2023-10-18 1d0e7419f2265432a3235d90c0428589cdb715b8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package nsq
 
import (
    "apsClient/conf"
    "apsClient/constvar"
    "apsClient/pkg/logx"
    "apsClient/pkg/nsqclient"
    "fmt"
)
 
func NewConsumer(topic, channel string) (c *nsqclient.NsqConsumer, err error) {
    c, err = nsqclient.NewNsqConsumer(topic, channel)
    if err != nil {
        logx.Errorf("NewNsqConsumer err:%v", err)
        return
    }
    logx.Infof("Consume NewNsqConsumer topic:%v", topic)
    var handler MsgHandler
    switch topic {
    case fmt.Sprintf(constvar.NsqTopicScheduleTask, conf.Conf.NsqConf.NodeId):
        handler = new(ScheduleTask)
    case fmt.Sprintf(constvar.NsqTopicSendPlcAddress, conf.Conf.NsqConf.NodeId):
        handler = &PlcAddress{Topic: topic}
    case fmt.Sprintf(constvar.NsqTopicProcessParamsResponse, conf.Conf.NsqConf.NodeId):
        handler = &ProcessParams{Topic: topic}
    case fmt.Sprintf(constvar.NsqTopicApsProcessParams, conf.Conf.NsqConf.NodeId):
        handler = &ProcessParamsSync{Topic: topic}
    case fmt.Sprintf(constvar.NsqTopicDeviceUpdate, conf.Conf.NsqConf.NodeId):
        handler = &DeviceUpdate{Topic: topic}
    case fmt.Sprintf(constvar.NsqTopicPullDataResponse, conf.Conf.NsqConf.NodeId):
        handler = &PullDataResponse{Topic: topic}
    }
    c.AddHandler(handler.HandleMessage)
    return
}