|
@@ -34,21 +34,9 @@ func NewController(rabbithost string) (*Controller, error) {
|
|
|
admin := msgQueue.NewRabbitMessageQueueAdmin(&msgQueue.RabbitMqSettings{Host: rabbithost}, nil)
|
|
|
producer := msgQueue.NewRabbitMqProducer(admin, "default")
|
|
|
consumer := msgQueue.NewRabbitConsumer(admin, "MAIN")
|
|
|
- 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 := initConsumers(consumer); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
if err := producer.Init(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -61,6 +49,25 @@ func NewController(rabbithost string) (*Controller, error) {
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
+func initConsumers(consumer *msgQueue.RabbitMqConsumer) error {
|
|
|
+ tService := &TenantService{}
|
|
|
+ tp := make([]*queue.TopicPartitionInfo, 0)
|
|
|
+
|
|
|
+ tenants, err := tService.FindTenants()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ for _, t := range tenants {
|
|
|
+ tp = append(tp, &queue.TopicPartitionInfo{
|
|
|
+ Topic: "MAIN",
|
|
|
+ TenantId: t.Id,
|
|
|
+ Partition: 0,
|
|
|
+ MyPartition: false,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return consumer.SubscribeWithPartitions(tp)
|
|
|
+}
|
|
|
+
|
|
|
// SetStatus 设置设备状态
|
|
|
func (c *Controller) SetStatus(args rpcs.ArgsSetStatus, reply *rpcs.ReplySetStatus) error {
|
|
|
rpchost, err := getAccessRPCHost(args.DeviceId)
|