简体   繁体   中英

I am using rabbitmq in Spring framework, how to call basicRecover on connection create?

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM