Ver código fonte

Update:nats优化为队列模式

zoie 9 meses atrás
pai
commit
bffd547225
2 arquivos alterados com 15 adições e 15 exclusões
  1. 14 14
      Nats/Nats.go
  2. 1 1
      controllers/Data.go

+ 14 - 14
Nats/Nats.go

@@ -47,7 +47,7 @@ func init() {
 func NatsInit() {
 
 	// 获取微信二维码 返回结果
-	_, _ = lib.Nats.Subscribe("Wx_BasicMessage_Event_QRCode", func(m *nats.Msg) {
+	_, _ = lib.Nats.QueueSubscribe("Wx_BasicMessage_Event_QRCode","Wx_BasicMessage_Event_QRCode", func(m *nats.Msg) {
 		//fmt.Printf(" => Nats   Wx_BasicMessage_Event_QRCode message: %s\n", string(m.Data))
 
 		type Person_QRCode struct {
@@ -113,7 +113,7 @@ func NatsInit() {
 	})
 
 	// 请求-响应 验证登录
-	_, _ = lib.Nats.Subscribe("Cold_User_verification", func(m *nats.Msg) {
+	_, _ = lib.Nats.QueueSubscribe("Cold_User_verification","Cold_User_verification", func(m *nats.Msg) {
 		fmt.Printf("Cold_User_verification message: %s\n", string(m.Data))
 
 		type T_R struct {
@@ -154,7 +154,7 @@ func NatsInit() {
 	})
 
 	// 请求-响应 通过公司名获取所有公司信息
-	_, _ = lib.Nats.Subscribe("Cold_User_CompanyListAllByT_name", func(m *nats.Msg) {
+	_, _ = lib.Nats.QueueSubscribe("Cold_User_CompanyListAllByT_name","Cold_User_CompanyListAllByT_name", func(m *nats.Msg) {
 		fmt.Printf("CompanyListAll message: %s\n", string(m.Data))
 
 		type T_R struct {
@@ -172,7 +172,7 @@ func NatsInit() {
 		_ = lib.Nats.Publish(m.Reply, b)
 	})
 	// 请求-响应 获取公司
-	_, _ = lib.Nats.Subscribe("Cold_ReadCompanyByT_id", func(m *nats.Msg) {
+	_, _ = lib.Nats.QueueSubscribe("Cold_ReadCompanyByT_id","Cold_ReadCompanyByT_id", func(m *nats.Msg) {
 		fmt.Printf("Cold_ReadCompanyByT_id message: %s\n", string(m.Data))
 
 		type T_R struct {
@@ -202,7 +202,7 @@ func NatsInit() {
 	})
 
 	// 请求-响应 获取所有用户列表
-	_, _ = lib.Nats.Subscribe("Cold_User_UserListAll", func(m *nats.Msg) {
+	_, _ = lib.Nats.QueueSubscribe("Cold_User_UserListAll","Cold_User_UserListAll", func(m *nats.Msg) {
 
 		type T_R struct {
 			Code int16             `xml:"Code"`
@@ -219,7 +219,7 @@ func NatsInit() {
 		_ = lib.Nats.Publish(m.Reply, b)
 	})
 	// 请求-响应 检查用户权限
-	_, _ = lib.Nats.Subscribe("Cold_User_CheckUserPermissions", func(m *nats.Msg) {
+	_, _ = lib.Nats.QueueSubscribe("Cold_User_CheckUserPermissions","Cold_User_CheckUserPermissions", func(m *nats.Msg) {
 		fmt.Printf("Cold_User_CheckUserPermissions message: %s\n", string(m.Data))
 		type T_Req struct {
 			Power_Id int    `xml:"Power_Id"` // 权限id
@@ -276,7 +276,7 @@ func NatsInit() {
 	})
 
 	// 发布-订阅 模式,异步订阅 AddSysLogs
-	_, _ = lib.Nats.Subscribe("Cold_User_AddSysLogs", func(m *nats.Msg) {
+	_, _ = lib.Nats.QueueSubscribe("Cold_User_AddSysLogs", "Cold_User_AddSysLogs", func(m *nats.Msg) {
 		fmt.Printf("AddSysLogs message: %s\n", string(m.Data))
 
 		type T_S struct {
@@ -299,7 +299,7 @@ func NatsInit() {
 	})
 
 	// 发布-订阅 模式,异步订阅 AddUserLogs
-	_, _ = lib.Nats.Subscribe("Cold_User_AddUserLogs", func(m *nats.Msg) {
+	_, _ = lib.Nats.QueueSubscribe("Cold_User_AddUserLogs", "Cold_User_AddUserLogs", func(m *nats.Msg) {
 		fmt.Printf("AddUserLogs message: %s\n", string(m.Data))
 
 		type T_S struct {
@@ -321,7 +321,7 @@ func NatsInit() {
 	})
 
 	// 请求-响应 获取设备
-	_, _ = lib.Nats.Subscribe("Cold_ReadDeviceByT_sn", func(m *nats.Msg) {
+	_, _ = lib.Nats.QueueSubscribe("Cold_ReadDeviceByT_sn","Cold_ReadDeviceByT_sn", func(m *nats.Msg) {
 		fmt.Printf("CheckUserPermissions message: %s\n", string(m.Data))
 
 		type T_R struct {
@@ -350,7 +350,7 @@ func NatsInit() {
 	})
 
 	// 请求-响应 获取传感器列表
-	_, _ = lib.Nats.Subscribe("Cold_ReadDeviceSensorALLByT_sn", func(m *nats.Msg) {
+	_, _ = lib.Nats.QueueSubscribe("Cold_ReadDeviceSensorALLByT_sn","Cold_ReadDeviceSensorALLByT_sn",  func(m *nats.Msg) {
 		fmt.Printf("CheckUserPermissions message: %s\n", string(m.Data))
 
 		type T_R struct {
@@ -372,7 +372,7 @@ func NatsInit() {
 	})
 
 	// 请求-响应 获取设备数据列表
-	_, _ = lib.Nats.Subscribe("Cold_ReadDeviceDataListBy_T_snid", func(m *nats.Msg) {
+	_, _ = lib.Nats.QueueSubscribe("Cold_ReadDeviceDataListBy_T_snid","Cold_ReadDeviceDataListBy_T_snid", func(m *nats.Msg) {
 		fmt.Printf("Cold_ReadDeviceDataListBy_T_snid message: %s\n", string(m.Data))
 		type T_Req struct {
 			T_snid     string `xml:"T_snid"`
@@ -411,7 +411,7 @@ func NatsInit() {
 	})
 
 	// 请求-响应 通过key获取传感器列表
-	_, _ = lib.Nats.Subscribe("Cold_CompanyDeviceSensor_List_ByKey", func(m *nats.Msg) {
+	_, _ = lib.Nats.QueueSubscribe("Cold_CompanyDeviceSensor_List_ByKey","Cold_CompanyDeviceSensor_List_ByKey",func(m *nats.Msg) {
 		fmt.Printf("Cold_CompanyDeviceSensor_List_ByKey message: %s\n", string(m.Data))
 		type T_Req struct {
 			T_sn  string `xml:"T_sn"`
@@ -460,7 +460,7 @@ func NatsInit() {
 	})
 
 	// 请求-响应 根据时间获取设备数据(单条)
-	_, _ = lib.Nats.Subscribe("Cold_ReadDeviceDataBy_T_snid_T_time", func(m *nats.Msg) {
+	_, _ = lib.Nats.QueueSubscribe("Cold_ReadDeviceDataBy_T_snid_T_time","Cold_ReadDeviceDataBy_T_snid_T_time", func(m *nats.Msg) {
 		fmt.Printf("Cold_ReadDeviceDataBy_T_snid_T_time message: %s\n", string(m.Data))
 		type T_Req struct {
 			T_sn string `xml:"T_sn"`
@@ -495,7 +495,7 @@ func NatsInit() {
 	})
 
 	// 请求-响应 获取设备
-	_, _ = lib.Nats.Subscribe("Cold_ReadDevice_List", func(m *nats.Msg) {
+	_, _ = lib.Nats.QueueSubscribe("Cold_ReadDevice_List","Cold_ReadDevice_List", func(m *nats.Msg) {
 		fmt.Printf("Cold_ReadDevice_List message: %s\n", string(m.Data))
 		type T_Req struct {
 			Key    string `xml:"Key"`

+ 1 - 1
controllers/Data.go

@@ -106,7 +106,7 @@ func (c *DataController) Device_Sensor_List() {
 	}
 
 	var cnt int64
-	Device.Read_DeviceSensorParameter_All_Map("", 0)
+	//Device.Read_DeviceSensorParameter_All_Map("", 0)
 	bindSN, err := Account.Read_UserDevice_List(c.Admin_r)
 	if err != nil {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}