相关疑难解决方法(0)

如何在Spring异步MessageListener用例中发生业务异常时请求RabbitMQ重试

我有一个Spring AMQP消息监听器正在运行.

public class ConsumerService implements MessageListener {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Override
    public void onMessage(Message message) {
        try {
            testService.process(message); //This process method can throw Business Exception
        } catch (BusinessException e) {
           //Here we can just log the exception. How the retry attempt is made?
        } catch (Exception e) {
           //Here we can just log the exception.  How the retry attempt is made?
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如您所见,在处理过程中可能会出现异常.我想重试因为Catch块中的特定错误.我不能通过onMessage中的异常.如何告诉RabbitMQ有异常并重试?

java spring rabbitmq

16
推荐指数
1
解决办法
9052
查看次数

标签 统计

java ×1

rabbitmq ×1

spring ×1