For one of the tests that I am doing I have an OpenWire.NET producer and
consumer that runs within Excel using a C# COM object to access ActiveMQ
using OpenWire.NET. It sends messages and then immediately consumes them.
When Excel quits on me I see that the messages get stuck on the queue
(through jconsole). When I restart Excel and res-subscribe my client I don't
get any messages even though messages are sitting on the queue. So my
OpenWire.NET code looks like (assume enable_async_receive is true):
public void CreateConnection(string url)
{
IConnectionFactory factory = new ConnectionFactory(new
Uri(url));
_jms_conn = factory.CreateConnection();
Console.WriteLine("Created a connection!");
_jms_session = _jms_conn.CreateSession();
Console.WriteLine("Session started!");
}
public void Subscribe(string queue, bool enable_async_receive)
{
IDestination destination = _jms_session.GetQueue(queue);
Console.WriteLine("Using destination: " + destination);
// lets create a consumer and producer
_consumer = _jms_session.CreateConsumer(destination);
if (enable_async_receive)
_consumer.Listener += new
MessageListener(_consumer_Listener);
_producer = _jms_session.CreateProducer(destination);
_producer.Persistent = false;
}
void _consumer_Listener(IMessage message)
{
lock (this)
{
OnMessageReceived(((ITextMessage)message).Text);
}
}
public string Receive()
{
IMessage message = _consumer.Receive();
if (message == null)
return null;
else
return ((ITextMessage) message).Text;
}
By trial and error I found out if I call the Receive() method above I seem
to unclog the queue and my event listener kicks back in. Any idea why this
happens?
P.S.: The provided example java consumer doesn't seem to have any problem
getting messages from the queue because I think it also just calls Receive()
a number of times and doesn't use a listener.
--
View this message in context:
http://www.nabble.com/Queue-gets-clogged-in-OpenWire.NET-when-using-Listener-tf2051829.html#a5652526
Sent from the ActiveMQ - User forum at Nabble.com.