如何防止rabbitmq服务器内的消息重新排队?

时间:2016-06-02 11:35:33

标签: spring rabbitmq message-queue

我正在使用直接交换将消息发布到带有路由密钥的某些队列,所有这些都配置在rabbit-server而不是代码中,我正在使用spring微服务消息,然后在接收方法中发生一些失败,然后消息重新排队导致循环,所以我想添加一个带有rabbit-server的策略来防止这种重新排队,可以在绑定队列与特定路由密钥交换时添加为参数,或者它应该是政策?

1 个答案:

答案 0 :(得分:0)

默认情况下弹出任何异常弹簧发送nack with requeue" true"。如果在你的spring consumer应用程序中你想发送requeue false,那么抛出异常" AmqpRejectAndDontRequeueException"。所以你的消费者代码应该像这样:

`void onMessage(){
  try{
    // Your Code Here
  } catch(Exception e){
     throw new AmqpRejectAndDontRequeueException();
  }
}`
相关问题