activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Holroyd <d...@badgers-in-foil.co.uk>
Subject NMS/MSMQ example code not working
Date Wed, 26 Sep 2007 23:11:30 GMT
I tried to adapt the NMS example code for MSMQ, but it seems to just
hangs trying to get the message back from MSMQ.  Under Computer
Management, I can see that a public queue gets created, but I've not
seen any messages listed there yet.

Please forgive my obvious lack of C# and MSMQ knowledge!


namespace Test {

	using System;
	using NMS;

	public class Bridge {

		public static void Main(string[] args) {

			IConnectionFactory factory = new MSMQ.ConnectionFactory();
			using (IConnection connection = factory.CreateConnection())
			{
			    Console.WriteLine("Created a connection!");
			    
			    ISession session = connection.CreateSession();
			    
			    IDestination destination = session.GetQueue(".\\BAR");
			    Console.WriteLine("Using destination: " + destination);
			    
			    // lets create a consumer and producer
			    IMessageConsumer consumer = session.CreateConsumer(destination);
			    
			    IMessageProducer producer = session.CreateProducer(destination);
			    producer.Persistent = true;
			    
			    // lets send a message
			    ITextMessage request = session.CreateTextMessage("Hello World!");
// commented out due to "Identifier is not in the incorrect format."
//			    request.NMSCorrelationID = "abc";
// commented out due to "Object reference not set to an instance of an object.",
//			    request.Properties["NMSXGroupID"] = "cheese";
//			    request.Properties["myHeader"] = "James";

			    // must have NMSType, or the MSMQ code fails,
			    request.NMSType = "Test";
			    
			    producer.Send(request);
			    
			    // lets consume a message
			    ITextMessage message = (ITextMessage) consumer.Receive();
			    if (message == null)
			    {
				Console.WriteLine("No message received!");
			    }
			    else
			    {
				Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
				Console.WriteLine("Received message with text: " + message.Text);
			    }
			}

		}
	}
}



-- 
http://david.holroyd.me.uk/

Mime
View raw message