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 Re: NMS/MSMQ example code not working
Date Mon, 01 Oct 2007 22:58:46 GMT
On Fri, Sep 28, 2007 at 10:39:37PM +0000, David Holroyd wrote:
> On Wed, Sep 26, 2007 at 11:11:30PM +0000, David Holroyd wrote:
> > 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.
> 
> So it looks like I have problems because the MSMQ stuff just isn't
> finished?
> 
> I'll try to add some of the missing pieces.

Please see

  https://issues.apache.org/activemq/browse/AMQNET-69

for some alterations that get me a bit further.  Here's a somewhat
working test program:


namespace Test {

	using System;
	using NMS;
	using System.IO;

	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
			    MemoryStream reqBuf = new MemoryStream();
			    StreamWriter writer = new StreamWriter(reqBuf);
			    writer.Write("Hello World!");
			    writer.Flush();
			    IBytesMessage request = session.CreateBytesMessage(reqBuf.ToArray());
// 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";

			    
			    producer.Send(request);
			    Console.WriteLine("msg sent");
			    
			    // lets consume a message
			    IBytesMessage message = (IBytesMessage)consumer.Receive();
			    if (message == null)
			    {
				Console.WriteLine("No message received!");
			    }
			    else
			    {
				Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
				MemoryStream buf = new MemoryStream(message.Content);
				StreamReader reader = new StreamReader(buf);
				Console.WriteLine("Received message with text: " + reader.ReadToEnd());
			    }
			}

		}
	}
}

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

Mime
View raw message