소스 검색

发送条通过

lcl 1 년 전
부모
커밋
facf64e982
4개의 변경된 파일48개의 추가작업 그리고 33개의 파일을 삭제
  1. 42 23
      AppStart/RabbitMQClient.cs
  2. 3 8
      AppStart/Service/MpOrderService.cs
  3. 1 0
      Startup.cs
  4. 2 2
      appsettings.Development.json

+ 42 - 23
AppStart/RabbitMQClient.cs

@@ -29,7 +29,7 @@ namespace MySystem
                 UserName = UserName,
                 Password = Password,
                 AutomaticRecoveryEnabled = true,  //如果connection挂掉是否重新连接
-                TopologyRecoveryEnabled = true  //连接恢复后,连接的交换机,队列等是否一同恢复
+                TopologyRecoveryEnabled = true,  //连接恢复后,连接的交换机,队列等是否一同恢复
             };
             List<AmqpTcpEndpoint> p = new List<AmqpTcpEndpoint>();
             string[] HostNames = HostName.Split(',');
@@ -40,34 +40,29 @@ namespace MySystem
             }
             var conn = factory.CreateConnection(p);
             var channel = conn.CreateModel();
-            channel.QueueDeclare(QueueName, true, false, false);
+            channel.QueueDeclare(QueueName);
             channel.BasicPublish("", QueueName, null, Encoding.Default.GetBytes(content));
             channel.Dispose();
             conn.Dispose();
         }
-        public void SendMsg(string QueueName)
+        public void SendMsg2(string content, string QueueName)
         {
             // 创建连接对象工厂
-            var factory = new ConnectionFactory()
-            {
-                UserName = UserName,
-                Password = Password,
-                AutomaticRecoveryEnabled = true,  //如果connection挂掉是否重新连接
-                TopologyRecoveryEnabled = true  //连接恢复后,连接的交换机,队列等是否一同恢复
-            };
-            List<AmqpTcpEndpoint> p = new List<AmqpTcpEndpoint>();
-            string[] HostNames = HostName.Split(',');
-            foreach (string subHostName in HostNames)
-            {
-                string[] subHostNameData = subHostName.Split(':');
-                p.Add(new AmqpTcpEndpoint(subHostNameData[0], int.Parse(subHostNameData[1])));
-            }
-            var conn = factory.CreateConnection(p);
-            var channel = conn.CreateModel();
-            channel.QueueDeclare(QueueName, true, false, false);
-            MpOrderService.Instance.dosomething(channel, QueueName);
-            channel.Dispose();
-            conn.Dispose();
+            // if (_connection == null)
+            // {
+            //     CreateConn();
+            // }
+            // else if (!_connection.IsOpen)
+            // {
+            //     CreateConn();
+            // }
+            // var channel = _connection.CreateModel();
+            // channel.ExchangeDeclare("kxs_direct_ranch", "direct", true);
+            // channel.QueueDeclare(QueueName, true, false, false);
+            // channel.QueueBind(QueueName, "kxs_direct_ranch", QueueName);
+            // channel.BasicPublish("", QueueName, null, Encoding.Default.GetBytes(content));
+            // channel.Dispose();
+            _channel_send.BasicPublish("", QueueName, null, Encoding.Default.GetBytes(content));
         }
         #endregion
 
@@ -133,6 +128,30 @@ namespace MySystem
         #endregion
 
         #region 单对单接收
+        public static IModel _channel_send;
+        public void CreateConn2(string QueueName)
+        { 
+            var factory = new ConnectionFactory()
+            {
+                UserName = UserName,
+                Password = Password,
+                AutomaticRecoveryEnabled = true,  //如果connection挂掉是否重新连接
+                TopologyRecoveryEnabled = true  //连接恢复后,连接的交换机,队列等是否一同恢复
+            };
+            List<AmqpTcpEndpoint> p = new List<AmqpTcpEndpoint>();
+            string[] HostNames = HostName.Split(',');
+            foreach (string subHostName in HostNames)
+            {
+                string[] subHostNameData = subHostName.Split(':');
+                p.Add(new AmqpTcpEndpoint(subHostNameData[0], int.Parse(subHostNameData[1])));
+            }
+            var conn = factory.CreateConnection(p);
+            _channel_send = conn.CreateModel();
+            _channel_send.ExchangeDeclare("kxs_direct_ranch", "direct", true);
+            _channel_send.QueueDeclare(QueueName, true, false, false);
+            _channel_send.QueueBind(QueueName, "kxs_direct_ranch", QueueName);
+        }
+
         public static IConnection _connection;
         public void CreateConn()
         { 

+ 3 - 8
AppStart/Service/MpOrderService.cs

@@ -16,17 +16,12 @@ namespace MySystem
 
         public void Start()
         {
-            Thread th = new Thread(SendMsg);
+            Thread th = new Thread(dosomething);
             th.IsBackground = true;
             th.Start();
         }
 
-        public void SendMsg()
-        {
-            RabbitMQClient.Instance.SendMsg("QUEUE_LKB_TRADE_DIVISION");
-        }
-
-        public void dosomething(IModel channel, string QueueName)
+        public void dosomething()
         {
             while (true)
             {
@@ -35,7 +30,7 @@ namespace MySystem
                 {
                     try
                     {
-                        channel.BasicPublish("", QueueName, null, Encoding.Default.GetBytes(content));
+                        RabbitMQClient.Instance.SendMsg2(content, "QUEUE_LKB_TRADE_DIVISION");
                     }
                     catch (Exception ex)
                     {                        

+ 1 - 0
Startup.cs

@@ -135,6 +135,7 @@ namespace MySystem
 
             //必须打开的
             RabbitMQClient.Instance.StartReceive("QUEUE_GD_ACT_DIVISION");
+            RabbitMQClient.Instance.CreateConn2("QUEUE_LKB_TRADE_DIVISION");
             MpOrderService.Instance.Start();
         }
     }

+ 2 - 2
appsettings.Development.json

@@ -27,7 +27,7 @@
     "MpSqlConnStr2": "server=47.109.31.237;port=3306;user=QrCodePlateMainServer;password=ll4DFaALMu9YIooM;database=QrCodePlateMainServer2;charset=utf8;",
     "RdsStatSqlConnStr": "server=rm-2vcu953x4yx7z454who.rwlb.cn-chengdu.rds.aliyuncs.com;user=KxsProfitServer;password=FrW8ZfxlcaVdm1r0;port=3306;database=KxsStatServer;charset=utf8;",
     "RedisConnStr": "47.108.62.166:6379,password=klm@redis,DefaultDatabase=1,poolsize=500,preheat=50,asyncPipeline=true",
-    "MpRedisConnStr": "8.137.99.48:6379,password=kxsmp@2023,DefaultDatabase=0,poolsize=500,preheat=50,asyncPipeline=true",
+    "MpRedisConnStr": "47.109.31.237:6379,password=klm@redis,DefaultDatabase=5,poolsize=500,preheat=50,asyncPipeline=true",
     "IOSAppVersion": "1.0.0",
     "AndroidAppVersion": "1.0.0",
     "OSSKey": "iL9dWgBunZRwGbHQ",
@@ -41,6 +41,6 @@
     "MqUserName": "admin",
     "MqPassword": "admin",
     "MqHostName": "47.109.61.191:5672",
-    "MqVirtualHostName": ""
+    "MqVirtualHostName": "/"
   }
 }