Переглянути джерело

入口队列通过配置取值

lcl 4 місяців тому
батько
коміт
3df5770656
4 змінених файлів з 21 додано та 14 видалено
  1. 6 6
      Common/RabbitMQClient.cs
  2. 7 0
      Model/Database/PriPrizeInSet.cs
  3. 2 2
      Program.cs
  4. 6 6
      Util/PrizeDo.cs

+ 6 - 6
Common/RabbitMQClient.cs

@@ -49,7 +49,7 @@ namespace MySystem
             }
             _connection = factory.CreateConnection(p);
         }
-        public void StartReceive(int QueueId, string Exchange = "", string RoutingKey = "")
+        public void StartReceive(string QueueName, string Exchange = "", string RoutingKey = "")
         {
             if (_connection == null)
             {
@@ -60,8 +60,8 @@ namespace MySystem
                 CreateConn();
             }
             var channel = _connection.CreateModel();
-            channel.QueueDeclare("PRIZE_SEND_QUEUE_" + QueueId, true, false, false, null);
-            channel.QueueBind("PRIZE_SEND_QUEUE_" + QueueId, Exchange, RoutingKey);
+            channel.QueueDeclare(QueueName, true, false, false, null);
+            channel.QueueBind(QueueName, Exchange, RoutingKey);
             channel.BasicQos(0, 1, false);
             EventingBasicConsumer consumer = new EventingBasicConsumer(channel);
             consumer.Received += (a, e) =>
@@ -70,7 +70,7 @@ namespace MySystem
                 try
                 {
                     Function.WriteLog(DateTime.Now.ToString() + "-" + MsgContent, "接收mq数据队列");
-                    PrizeDo.sendPrize(QueueId, MsgContent);
+                    PrizeDo.sendPrize(QueueName, MsgContent);
                     Function.WriteLog(DateTime.Now.ToString() + "-end", "接收mq数据队列");
                 }
                 catch(Exception ex)
@@ -79,7 +79,7 @@ namespace MySystem
                 }
                 channel.BasicAck(e.DeliveryTag, false); //收到回复后,RabbitMQ会直接在队列中删除这条消息
             };
-            channel.BasicConsume("PRIZE_SEND_QUEUE_" + QueueId, false, consumer);
+            channel.BasicConsume(QueueName, false, consumer);
         }
         public void Start()
         {
@@ -87,7 +87,7 @@ namespace MySystem
             var list = setService.GetList(m => m.status == 1);
             foreach(var sub in list)
             {
-                StartReceive(sub.id, "PRIZE_SEND_QUEUE", "/");
+                StartReceive(sub.mqQueueName, "PRIZE_SEND_QUEUE", "/");
             }
         }
         #endregion

+ 7 - 0
Model/Database/PriPrizeInSet.cs

@@ -73,6 +73,13 @@ namespace Model
         public string? note { get; set; }
 
 
+        /// <summary>
+        /// MQ队列名
+        /// </summary>
+        [SugarColumn(ColumnDescription = "MQ队列名", Length = 50, ColumnName = "mq_queue_name")]
+        public string? mqQueueName { get; set; }
+
+
 
     }
 }

+ 2 - 2
Program.cs

@@ -125,11 +125,11 @@ app.MapControllers();
 // PrizeDo.sendPrize(4, "{\"PosSn\":\"CS00000000015859\"}");
 // PrizeDo.sendPrize(5, "{\"PosSn\":\"00000302T1NL90664172\"}");
 // PrizeDo.sendPrize(6, "{\"PosSn\":\"1152131239\"}");
-PrizeDo.sendPrize(3, "{\"order_id\":\"319698\"}");
+// PrizeDo.sendPrize(3, "{\"order_id\":\"319698\"}");
 // PrizeDo.sendPrize(7, "{\"OrderNo\":\"BM2024090817330511847441249\"}");
 // PrizeDo.sendPrize(7, "{\"OrderNo\":\"BM2024090817360962275551251\"}");
 
-// RabbitMQClient.Instance.Start();
+RabbitMQClient.Instance.Start();
 
 // PrizeDo.sendPrize("{\"prize_tag\":\"1\",\"content\":\"{\\\"PosSn\\\":\\\"00002402045980195457\\\"}\"}");
 

+ 6 - 6
Util/PrizeDo.cs

@@ -17,16 +17,17 @@ namespace Util
         public static string batchNo = "";
         public static string publicStep = "";
         //发奖入口
-        public static void sendPrize(int prizeInId, string content)
+        public static void sendPrize(string queueName, string content)
         {
             batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(3);
             publicStep = "";
-            string priObjString = prizeInSet(prizeInId);
+            string priObjString = prizeInSet(queueName);
             if(!string.IsNullOrEmpty(priObjString))
             {
                 string[] priObjData = priObjString.Split('|');
                 string priListIds = priObjData[0];
                 int projectId = int.Parse(priObjData[1]);
+                int prizeInId = int.Parse(priObjData[2]);
                 prizeSend(projectId, prizeInId, priListIds, content);
             }
         }
@@ -532,16 +533,15 @@ namespace Util
         }
 
         //奖励发放入口
-        public static string prizeInSet(int prizeObjectTag)
+        public static string prizeInSet(string queueName)
         {
             Dictionary<string, object> dic = new Dictionary<string, object>();
             var prizeInSetService = App.GetService<IPriPrizeInSetService>();
             //查询表
-            var prizeInSet = prizeInSetService.GetFirst(m => m.id == prizeObjectTag) ?? new PriPrizeInSet();
+            var prizeInSet = prizeInSetService.GetFirst(m => m.mqQueueName == queueName) ?? new PriPrizeInSet();
             if(prizeInSet.id > 0)
             {
-                int projectId = prizeInSet.projectId;
-                return prizeInSet.prizeListIds + "|" + projectId;
+                return prizeInSet.prizeListIds + "|" + prizeInSet.projectId + "|" + prizeInSet.id;
             }
             return "";
         }