日期:2014-05-17 浏览次数:21035 次
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 } }
通过NMS连接 下载NMS 下载地址:http://www.springframework.net/downloads/Spring.Messaging.Nms/ 我们需要用到 Spring.Core ActiveMQ NMS Spring.Messaging.NMS 几个DLL