123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Apache.NMS;
- using Apache.NMS.ActiveMQ;
- using Apache.NMS.Util;
- using Newtonsoft.Json;
- using wms.util.Http;
- namespace wms.workservice
- {
- public class ConService
- {
- System.IO.StreamWriter streamWriter = new("E:\\log.txt", true);
- public void WriteLog(string str)
- {
- streamWriter.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff") + " ==== " + str);
- }
- public void FJConsumer()
- {
- streamWriter.WriteLine("启动分拣消费");
- string queuesName = "ESB.OUT.163LFJ.Q";
- string confuri = wms.util.AppSettings.GetConfig("MqTcpUri:fjurl");
- //Uri _uri = new Uri(String.Concat("activemq: failover:(tcp://esb-pre.zt.net.cn:61616?wireFormat.maxInactivityDuration-0)"));
- Uri _uri = new Uri(String.Concat("activemq:failover:(" + confuri + ")?randomize=false"));
- IConnectionFactory factory = new ConnectionFactory(_uri);
- IConnection conn = factory.CreateConnection("esbadminrw", "esbadminrw");
- Apache.NMS.ISession session = conn.CreateSession();
- conn.Start();
- IDestination destination = SessionUtil.GetDestination(session, queuesName);
- IMessageConsumer consumer = session.CreateConsumer(destination);
- consumer.Listener += (IMessage message) =>
- {
- ITextMessage msg = (ITextMessage)message;
- Console.WriteLine("接收消息:" + msg.Text);
- streamWriter.WriteLine("分拣消费接收消息" + msg.Text);
- foreach (var key in msg.Properties.Keys.Cast<string>())
- {
- var keyvalue = message.Properties[key];
- if (keyvalue != null && key == "serviceCode")
- {
- if (wms.util.AppSettings.GetConfig("ApiUrl:"+keyvalue.ToString()) != null)
- {
- var aa = wms.util.AppSettings.GetConfig("ApiUrl:" + keyvalue.ToString());
- //streamWriter.WriteLine("分拣消费post调用请求:" + wms.util.AppSettings.GetConfig("ApiUrl:" + keyvalue.ToString()));
- //var res = HttpUtil.PostRequest(wms.util.AppSettings.GetConfig("ApiUrl:" + keyvalue.ToString()), msg.Text, 30000);
- //streamWriter.WriteLine("分拣消费post调用返回:" + res);
- }
- Console.WriteLine("接收消息:" + message.Properties[key]);
- }
- }
- };
-
-
- }
- }
- }
|