Răsfoiți Sursa

启动奖励mq

lcl 1 an în urmă
părinte
comite
5852fd2829
3 a modificat fișierele cu 80 adăugiri și 2 ștergeri
  1. 1 1
      AppStart/RabbitMQPrize.cs
  2. 77 0
      AppStart/Service/PrizeSendService.cs
  3. 2 1
      Startup.cs

+ 1 - 1
AppStart/RabbitMQPrize.cs

@@ -24,7 +24,7 @@ namespace MySystem
         public void SendMsg(string content, string QueueName)
         {
             _channel_send.BasicPublish("", QueueName, null, Encoding.Default.GetBytes(content));
-            function.WriteLog(DateTime.Now.ToString() + "\n" + QueueName + "\n" + content + "\n\n\n", "SendMsg2");
+            function.WriteLog(DateTime.Now.ToString() + "\n" + QueueName + "\n" + content + "\n\n\n", "发送奖励原始数据");
         }
         #endregion
 

+ 77 - 0
AppStart/Service/PrizeSendService.cs

@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using Library;
+using System.Linq;
+using System.Threading;
+using System.Text;
+
+namespace MySystem
+{
+    public class PrizeSendService
+    {
+        public readonly static PrizeSendService Instance = new PrizeSendService();
+        private PrizeSendService()
+        { }
+
+        public void Start()
+        {
+            Thread th = new Thread(dosomething);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void dosomething()
+        {
+            while (true)
+            {
+                string content = RedisDbconn.Instance.RPop<string>("PrizeSendQueue");
+                if (!string.IsNullOrEmpty(content))
+                {
+                    try
+                    {
+                        RabbitMQPrize.Instance.SendMsg(content, "PRIZE_SEND_QUEUE");
+                    }
+                    catch (Exception ex)
+                    {                        
+                        function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "推送客小爽机具数据异常");
+                    }
+                }
+                else
+                {
+                    Thread.Sleep(2000);
+                }
+            }
+        }
+
+
+        public void StartMp()
+        {
+            Thread th = new Thread(dosomethingMp);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void dosomethingMp()
+        {
+            while (true)
+            {
+                string content = MpRedisDbconn.Instance.RPop<string>("KxsActQueue");
+                if (!string.IsNullOrEmpty(content))
+                {
+                    try
+                    {
+                        RabbitMQClient.Instance.SendMsg3(content, "QUEUE_KXS_ACT_DIVISION");
+                    }
+                    catch (Exception ex)
+                    {                        
+                        function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "推送客小爽码牌激活数据异常");
+                    }
+                }
+                else
+                {
+                    Thread.Sleep(500);
+                }
+            }
+        }
+    }
+}

+ 2 - 1
Startup.cs

@@ -143,7 +143,8 @@ namespace MySystem
             KxsOrderService.Instance.Start();
             KxsActService.Instance.Start();
             KxsActService.Instance.StartMp();
-            RabbitMQClient.Instance.StartReceiveApi("QUEUE_DTS_URL_DATA_DIVISION");
+            PrizeSendService.Instance.Start();
+            // RabbitMQClient.Instance.StartReceiveApi("QUEUE_DTS_URL_DATA_DIVISION");
         }
     }
 }