|
@@ -32,21 +32,27 @@ func NewController(rabbithost string) (*Controller, error) {
|
|
|
admin := msgQueue.NewRabbitMessageQueueAdmin(&msgQueue.RabbitMqSettings{Host: rabbithost}, nil)
|
|
|
producer := msgQueue.NewRabbitMqProducer(admin, "default")
|
|
|
consumer := msgQueue.NewRabbitConsumer(admin, "MAIN")
|
|
|
- _ = consumer.Subscribe()
|
|
|
- //// timer
|
|
|
- //t := rule.NewTimer()
|
|
|
- //t.Run()
|
|
|
- //
|
|
|
- //// ifttt
|
|
|
- //ttt := rule.NewIfttt()
|
|
|
+ tp := make([]*queue.TopicPartitionInfo, 0)
|
|
|
+ tp = append(tp, &queue.TopicPartitionInfo{
|
|
|
+ Topic: "MAIN",
|
|
|
+ TenantId: "1ps9djpswi0cds7cofynkso300eql4iu",
|
|
|
+ Partition: 0,
|
|
|
+ MyPartition: false,
|
|
|
+ })
|
|
|
+ tp = append(tp, &queue.TopicPartitionInfo{
|
|
|
+ Topic: "MAIN",
|
|
|
+ TenantId: "1ps9djpswi0cds7cofynkso300eql4sw",
|
|
|
+ Partition: 0,
|
|
|
+ MyPartition: false,
|
|
|
+ })
|
|
|
+ _ = consumer.SubscribeWithPartitions(tp)
|
|
|
+
|
|
|
if err := producer.Init(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
return &Controller{
|
|
|
producer: producer,
|
|
|
- // timer: t,
|
|
|
- // ift: ttt,
|
|
|
consumer: consumer,
|
|
|
cluster: &ClusterService{producer: producer},
|
|
|
pool: grpool.New(),
|
|
@@ -137,6 +143,47 @@ func (c *Controller) processStatusToQueue(args rpcs.ArgsOnStatus) (string, error
|
|
|
return result, nil
|
|
|
}
|
|
|
|
|
|
+func (c *Controller) processEventToQueue(args rpcs.ArgsOnEvent) (string, error) {
|
|
|
+ var result string
|
|
|
+ device := &models.Device{}
|
|
|
+ err := server.RPCCallByName(nil, rpcs.RegistryServerName, "Registry.FindDeviceByRecordId", &rpcs.ArgsDeviceAuth{DeviceID: args.DeviceId}, device)
|
|
|
+ if err != nil {
|
|
|
+ server.Log.Errorf("find device error : %v", err)
|
|
|
+ return result, err
|
|
|
+ }
|
|
|
+
|
|
|
+ product := &models.Product{}
|
|
|
+ err = server.RPCCallByName(nil, rpcs.RegistryServerName, "Registry.FindProduct", &device.ProductID, product)
|
|
|
+ if err != nil {
|
|
|
+ server.Log.Errorf("find product error : %v", err)
|
|
|
+ return result, err
|
|
|
+ }
|
|
|
+
|
|
|
+ pc, err := productconfig.New(product.ProductConfig)
|
|
|
+ if err != nil {
|
|
|
+ server.Log.Errorf("product config error : %v", err)
|
|
|
+ return result, err
|
|
|
+ }
|
|
|
+ ev := &protocol.Event{}
|
|
|
+ ev.Head.SubDeviceid = args.SubDevice
|
|
|
+ ev.Head.Priority = args.Priority
|
|
|
+ ev.Head.No = args.No
|
|
|
+ ev.Head.Timestamp = args.TimeStamp
|
|
|
+ ev.Head.ParamsCount = uint16(len(args.Params))
|
|
|
+ ev.Params = args.Params
|
|
|
+ m, err := pc.EventToMap(ev)
|
|
|
+ if err != nil {
|
|
|
+ server.Log.Errorf("gen status json error : %v", err)
|
|
|
+ return result, err
|
|
|
+ }
|
|
|
+ b, err := json.Marshal(&m)
|
|
|
+ if err != nil {
|
|
|
+ server.Log.Errorf("marshal json error : %v", err)
|
|
|
+ }
|
|
|
+ result = string(b)
|
|
|
+ return result, nil
|
|
|
+}
|
|
|
+
|
|
|
func (c *Controller) OnEvent(args rpcs.ArgsOnEvent, reply *rpcs.ReplyOnEvent) error {
|
|
|
go func() {
|
|
|
err := c.ift.Check(args.DeviceId, args.No)
|
|
@@ -223,7 +270,6 @@ func (c *Controller) launchConsumer() {
|
|
|
fmt.Println("解析消息失败")
|
|
|
}
|
|
|
tanantId := msg.GetHeaders().Get("tanant_id")
|
|
|
- server.Log.Debugf("tanant_id:%s", tanantId)
|
|
|
if c.actorContext != nil {
|
|
|
c.actorContext.Tell(&ruleEngine.QueueToRuleEngineMsg{
|
|
|
TenantId: string(tanantId),
|