You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by David Holroyd <da...@badgers-in-foil.co.uk> on 2007/09/27 01:11:30 UTC
NMS/MSMQ example code not working
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/
Re: NMS/MSMQ example code not working
Posted by David Holroyd <da...@badgers-in-foil.co.uk>.
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/
Re: NMS/MSMQ example code not working
Posted by David Holroyd <da...@badgers-in-foil.co.uk>.
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.
--
http://david.holroyd.me.uk/