tags:

views:

624

answers:

5

I have written a windows service using the Apache.NMS and Apcahe.NMS.ActiveMQ (version 1.0) libraries. The service consumes messages from ActiveMQ from a vendor server.

The service spins up a connection and listens for messages (I handle the OnMessage event)

The connection is a transacted connection so I call commit after each message.

When the service starts up, everything works very well and does so for a while. However, after it has run for a while, it will no longer consume messages. Even if I reset the service. It usually takes a restart of my service AND the vendor server (tomcat) to get things going again. The vendor insists that nothing is wrong on their side.

No exceptions are thrown on either side (client or server) - it's just 'stuck'.

Should I consider using Spring.Messaging.Nms?

+1  A: 

I have discovered the problem. After establishing the connection and the message listener the service went into a loop with Thread.Sleep(500). Dumb. I refactored the service to start everything up in OnStart and dispose of it in OnStop.

Since doing that, everything is running perfectly.

Classic ID-10-T error occurring between keyboard and chair.

Loki Stormbringer
A: 

Hi Rick,

we have just come across exactly the same issue using a .Net service talking to ActiveMQ, but ours locks up after only about 10-20 messages being delivered.

Have tried it with and without the spring framework and it's slightly better without (unless I'm imagining things).

Would you mind checking over this code and letting me know if it bears any resemblance to your own?

ConnectionFactory connectionFactory = new ConnectionFactory("tcp://activemq:61616");

Connection connection = (Connection)connectionFactory.CreateConnection();
connection.Start();

Session session = (Session)connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
IDestination queue = session.GetQueue("test.queue");

MessageConsumer consumer = (MessageConsumer)session.CreateConsumer(queue);

for (int i = 0; i < 1000; i++)
{
    IMessage msg = consumer.Receive();
    if (msg != null)
     Console.WriteLine((msg as ITextMessage).Text);
}

Cheers,

Rob

theGecko
+1  A: 

My code is a little different. Instead of polling in a loop I set up a listener that responds to an "OnMessage" event. My code is similar to the code below. My actual code has lot of irrelevant stuff in it but the spirit is the same - hope this helps.

factory = new Apache.NMS.ActiveMQ.ConnectionFactory("tcp://activemq:61616");

connection = factory.QueueConnection(factory, "MyQueue", AcknowledgementMode.AutoAcknowledge)

consumer = connection.Session.CreateConsumer(connection.Queue, "2 > 1"); //Get every msg

consumer.Listener += new MessageListener(OnMessage);

private void OnMessage(IMessage message) { //Process message here.; }

Loki Stormbringer
A: 

Thanks very much, Rick.

Any idea where the factory.QueueConnection() function has come from, it doesn't seem to be in the latest release :/

theGecko
+1  A: 

Never mind, I found it here:

Transactional Message Processing with ActiveMQ and NMS

Cheers,

Rob

theGecko