1、添加对 Apache.NMS Apache.NMS.ActiveMQ引用;

  ActiveMQ .NET   http://activemq.apache.org/nms/index.html

2、在webconfig中添加调用MQ所需的MQIP,MQName,MQUserName,MQPassword;

.net客户端调用activeMQ代码  <appSettings>
.net客户端调用activeMQ代码    
<add key="MQIP" value="XX" />
.net客户端调用activeMQ代码    
<add key="MQName" value="XX" />
.net客户端调用activeMQ代码    
<add key="MQUsername" value="XX" />
.net客户端调用activeMQ代码    
<add key="MQPassword" value="XX" />
.net客户端调用activeMQ代码  
</appSettings>

3、创建一个通用的调用类。

    

.net客户端调用activeMQ代码using System;
.net客户端调用activeMQ代码
using System.Collections.Generic;
.net客户端调用activeMQ代码
using System.Linq;
.net客户端调用activeMQ代码
using System.Text;
.net客户端调用activeMQ代码
.net客户端调用activeMQ代码
.net客户端调用activeMQ代码
using Apache.NMS;
.net客户端调用activeMQ代码
using Apache.NMS.ActiveMQ;
.net客户端调用activeMQ代码
using Apache.NMS.ActiveMQ.Commands;
.net客户端调用activeMQ代码
.net客户端调用activeMQ代码
namespace Lee.Client

4、调用

.net客户端调用activeMQ代码using System;
.net客户端调用activeMQ代码
using System.Collections.Generic;
.net客户端调用activeMQ代码
using System.Linq;
.net客户端调用activeMQ代码
using System.Text;
.net客户端调用activeMQ代码
.net客户端调用activeMQ代码
namespace Lee.Client

 -------------20100107----------
改进调用类
IMessageProducer和ISession都继承了IDisposable接口,所以创建对象producer和session时使用Using。

    public static void SendMessage(string ip, string mqName, string mqUsername, string mqPassword, string userID, string subsysID, int cent, string summary)
    {
            IConnectionFactory factory 
= new ConnectionFactory(new Uri("tcp://" + ip));
            
using (IConnection connection = factory.CreateConnection(mqUsername, mqPassword))
            {
                
using (ISession session = connection.CreateSession())
                {
                    ActiveMQQueue destination 
= (ActiveMQQueue)session.GetQueue(mqName);
                    
using (IMessageProducer producer = session.CreateProducer(destination))
                    {
                        producer.Persistent 
= true;
                        IMapMessage request 
= session.CreateMapMessage();
                        request.Body.SetString(
"userID", userID);
                        request.Body.SetString(
"subsysID", subsysID);
                        request.Body.SetInt(
"cent", cent);
                        request.Body.SetString(
"summary", summary);
                        producer.Send(destination, request);
                    }
                }
            }

    }



相关文章:

  • 2021-12-30
  • 2021-12-25
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2022-02-14
猜你喜欢
  • 2022-01-15
  • 2021-11-22
  • 2021-11-25
  • 2022-12-23
  • 2021-12-20
相关资源
相似解决方案