Announcement Announcement Module
No announcement yet.
Cancelling AmqpTemplate.receiveAndConvert() Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cancelling AmqpTemplate.receiveAndConvert()


    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.


  • #2
    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?


    • #3

      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?

      [email protected]1, prio=5, in group 'main', status: 'waiting'
      java.lang.Thread.State: WAITING
      at java.lang.Object.wait(
      at java.lang.Object.wait(
      at com.rabbitmq.utility.BlockingCell.get(BlockingCell .java:50)
      at com.rabbitmq.utility.BlockingCell.uninterruptibleG et(
      at com.rabbitmq.utility.BlockingValueOrException.unin terruptibleGetValue( 33)
      at com.rabbitmq.client.impl.AMQChannel$BlockingRpcCon tinuation.getReply(
      at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQ
      at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc (
      at com.rabbitmq.client.impl.ChannelN.basicGet(Channel
      at sun.reflect.GeneratedMethodAccessor3.invoke(Unknow n Source:-1)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(De
      at java.lang.reflect.Method.invoke(
      at org.springframework.amqp.rabbit.connection.Caching ConnectionFactory$CachedChannelInvocationHandler.i nvoke(
      - locked <0x9eb> (a java.lang.Object)
      at $Proxy6.basicGet(Unknown Source:-1)
      at org.springframework.amqp.rabbit.core.RabbitTemplat e$2.doInRabbit(
      at org.springframework.amqp.rabbit.core.RabbitTemplat e$2.doInRabbit(
      at org.springframework.amqp.rabbit.core.RabbitTemplat e.execute(
      at org.springframework.amqp.rabbit.core.RabbitTemplat e.receive(
      at org.springframework.amqp.rabbit.core.RabbitTemplat e.receiveAndConvert(
      ..... etc


      • #4
        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?


        • #5
          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."


          • #6
            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?