ActiveMQ.net client is blocked

I wrote a Windows service using the Apache.NMS and Apcahe.NMS.ActiveMQ libraries (version 1.0). The service spends messages from ActiveMQ from the provider's server.

The service joins the connection and listens for messages (I am handling the OnMessage event)

A connection is a transactional connection, so I call commit after each message.

When the service starts, everything works very well and does this for a while. However, after it starts for a while, it will no longer consume messages. Even if I reset the service. It usually takes a reboot of my service and the provider server (tomcat) to get started again. The seller insists that there is nothing wrong with them.

No exceptions are thrown from each side (client or server) - it just gets stuck.

Should I use Spring.Messaging.Nms?

+1
source share
4 answers

I have discovered a problem. After establishing a connection and a message listener, the service went into a loop with Thread.Sleep (500). Stupid. I reorganized the service to run everything on OnStart and get rid of it on OnStop.

Everything has been working fine ever since.

A classic ID-10-T error that occurs between a keyboard and a chair.

+3
source

. , "OnMessage". . , - , .

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.;
}
+1
+1

, .NET, ActiveMQ, 10-20 .

spring , ( , ).

, - ?

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);
}
0

All Articles