在C#中怎么实现ActiveMQ的连接?
推荐于2016-06-16
展开全部
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using ActiveMQ;
using Spring.Messaging.Nms;
using Spring.Messaging.Nms.Listener;
namespace ListenerConsole
{
class Program
{
private const string URI = "tcp://localhost:61616";
private const string DESTINATION = "test.queue";
static void Main(string[] args)
{
try
{
ConnectionFactory connectionFactory = new ConnectionFactory(URI);
using (SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer())
{
listenerContainer.ConnectionFactory = connectionFactory;
listenerContainer.DestinationName = DESTINATION;
listenerContainer.MessageListener = new Listener();
listenerContainer.AfterPropertiesSet();
Console.WriteLine("Listener started.");
Console.WriteLine("Press <ENTER> to exit.");
Console.ReadLine();
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.WriteLine("Press <ENTER> to exit.");
Console.Read();
}
}
}
}
using System;
using Spring.Messaging.Nms;
using NMS;
namespace ListenerConsole
{
class Listener : IMessageListener
{
public Listener()
{
Console.WriteLine("Listener created.rn");
}
#region IMessageListener Members
public void OnMessage(NMS.IMessage message)
{
ITextMessage textMessage = message as ITextMessage;
Console.WriteLine(textMessage.Text);
}
#endregion
}
}
using System.Collections.Generic;
using System.Text;
using System.Threading;
using ActiveMQ;
using Spring.Messaging.Nms;
using Spring.Messaging.Nms.Listener;
namespace ListenerConsole
{
class Program
{
private const string URI = "tcp://localhost:61616";
private const string DESTINATION = "test.queue";
static void Main(string[] args)
{
try
{
ConnectionFactory connectionFactory = new ConnectionFactory(URI);
using (SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer())
{
listenerContainer.ConnectionFactory = connectionFactory;
listenerContainer.DestinationName = DESTINATION;
listenerContainer.MessageListener = new Listener();
listenerContainer.AfterPropertiesSet();
Console.WriteLine("Listener started.");
Console.WriteLine("Press <ENTER> to exit.");
Console.ReadLine();
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.WriteLine("Press <ENTER> to exit.");
Console.Read();
}
}
}
}
using System;
using Spring.Messaging.Nms;
using NMS;
namespace ListenerConsole
{
class Listener : IMessageListener
{
public Listener()
{
Console.WriteLine("Listener created.rn");
}
#region IMessageListener Members
public void OnMessage(NMS.IMessage message)
{
ITextMessage textMessage = message as ITextMessage;
Console.WriteLine(textMessage.Text);
}
#endregion
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询