1

I am using rabbitmq spring framework. There is an issue with my queues, during my rabbitmq consumer deployment, the suddenly disconnect will left unacked messages behind.

<rabbit:listener-container id="MyListenerContainer"
    connection-factory="MyRabbitConsumerConnectionFactory"
    prefetch="100"
    concurrency="5"
    acknowledge="manual"
    auto-startup="true">
    <rabbit:listener queues="MyRabbitQueue" ref="MyConsumer"/>

<rabbit:queue id="MyRabbitQueue"
              name="MyRabbitQueue"
              declared-by="MyConsumerRabbitAdmin"
              auto-delete="false"
              durable="true"
              exclusive="false"/>

<rabbit:admin id="MyConsumerRabbitAdmin"
              connection-factory="MyRabbitConsumerConnectionFactory"
              auto-startup="true"/>

MyConsumer implemented ChannelAwareMessageListener interface. How can I issue basicRecover(true) method during connection create?

Thanks

Ben
  • 35
  • 4

2 Answers2

0

Try to play with com.rabbitmq.client.ConnectionFactory:

/**
 * Enables or disables <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>.
 * @param automaticRecovery if true, enables connection recovery
 * @see <a href="http://www.rabbitmq.com/api-guide.html#recovery">Automatic Recovery</a>
 */
public void setAutomaticRecoveryEnabled(boolean automaticRecovery) {
    this.automaticRecovery = automaticRecovery;
}

it is false by default.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • I have enabled automaticRecovery. I can got connection recovered. My issue after I stop my consumer (stop the process of my consumer), and then restart it later. There are many unacked message left behind at the moment of the stop consumer. So I want to call basicRecover when the first time connection got established. – Ben Oct 01 '15 at 20:54
  • I don't want speculate and copy/paste, so I'm sending you to the proper link: http://stackoverflow.com/questions/7063224 – Artem Bilan Oct 01 '15 at 21:58
  • I added a channelListener on ConnectionFactory. in onCreate method, I will issue channel.basicRecover(true). I have one concern, the redelivered messages have redelivery flag set as true due to channel.basicRecover(true)? – Ben Oct 05 '15 at 18:21
  • From my perspective it's correct. Your messages has been delivered once already. So, that good that recovery track it and let your new consumer know that there was something unexpected before. – Artem Bilan Oct 05 '15 at 18:37
  • is the redelivered flag set as true in this case? – Ben Oct 05 '15 at 18:41
  • Sorry, I don't know, but your experiments confirm that (see your comment above). Isn't it ? – Artem Bilan Oct 05 '15 at 18:43
0

You could use the RabbitMQ Management HTTP API to list all the channels, then on the details of each channel you can see how long it has been idle and react accordingly, closing the channel for example, which would automatically nack any un-acked messages still hanging around on that channel.

See here: http://hg.rabbitmq.com/rabbitmq-management/raw-file/3646dee55e02/priv/www-api/help.html

Acorn
  • 834
  • 7
  • 3