Oct 20th, 2011, 07:30 PM
from my main thread I am creating a separate thread that calls to AmqpTemplate.receiveAndConvert() and is blocking waiting for a message.
How can I cancel the AmqpTemplate.receiveAndConvert() from my main thread?
I can't call Thread.interrupt() on the receiving thread because RabbitMQ swallows this exception. My thread is in com.rabbitmq.utility.BlockingCell.uninterruptibleG et().
Any suggestions would be appreciated.
Oct 22nd, 2011, 06:51 AM
Rabbit receive calls are not blocking, so there must be something else going on there. Can you post a bit more of your stack dump?
Oct 26th, 2011, 01:24 AM
I'm not sure what you mean about rabbit receive calls being non-blocking. I thought AmqpTemplate.receiveAndConvert() was a blocking call?
Below is the stack dump of my thread that is waiting for a message. There doesn't seem to be anything in the AmqpTemplate or AmqpAdmin interfaces that would allow me to cancel my waiting for a message.
I guess I would need to use the Rabbit MQ client directly to do such things?
main@1, prio=5, in group 'main', status: 'waiting'
at com.rabbitmq.utility.BlockingCell.get(BlockingCell .java:50)
at com.rabbitmq.utility.BlockingCell.uninterruptibleG et(BlockingCell.java:89)
at com.rabbitmq.utility.BlockingValueOrException.unin terruptibleGetValue(BlockingValueOrException.java: 33)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcCon tinuation.getReply(AMQChannel.java:337)
at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQ Channel.java:210)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc (AMQChannel.java:128)
at com.rabbitmq.client.impl.ChannelN.basicGet(Channel N.java:808)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknow n Source:-1)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at org.springframework.amqp.rabbit.connection.Caching ConnectionFactory$CachedChannelInvocationHandler.i nvoke(CachingConnectionFactory.java:298)
- locked <0x9eb> (a java.lang.Object)
at $Proxy6.basicGet(Unknown Source:-1)
at org.springframework.amqp.rabbit.core.RabbitTemplat e$2.doInRabbit(RabbitTemplate.java:269)
at org.springframework.amqp.rabbit.core.RabbitTemplat e$2.doInRabbit(RabbitTemplate.java:267)
at org.springframework.amqp.rabbit.core.RabbitTemplat e.execute(RabbitTemplate.java:408)
at org.springframework.amqp.rabbit.core.RabbitTemplat e.receive(RabbitTemplate.java:267)
at org.springframework.amqp.rabbit.core.RabbitTemplat e.receiveAndConvert(RabbitTemplate.java:296)
Oct 26th, 2011, 05:46 AM
It's not supposed to wait at all. If the broker has no message on that queue you should just get back null. Quickly. The Rabbit client must be having some issues, but I'm not sure exactly what that might be. What version of the client and broker is it?
Oct 26th, 2011, 06:10 PM
I'm pretty sure it's a blocking call. That's what I'm seeing and that is what the documentation says. See section 2.5 "Receiving Messages". It says "The simpler option is to poll for a single Message at a time with a synchronous, blocking method call."
Oct 27th, 2011, 05:43 AM
Sorry, I think we have a misunderstanding - probably my fault. The receive() methods are indeed blocking, but they do not wait for a message to arrive before returning, so the only explanation that makes any sense to me for your apparent long wait, is a bug in the client or the broker. That's why I asked about the versions. Is this reproducible?