【发布时间】:2016-10-12 03:35:01
【问题描述】:
我有一个单独的发布者和消费者。我启动发布者并发布消息。现在我启动消费者,问题是消息从就绪队列移动到取消确认队列,将消息标记为重新传递,这是我想要避免的。所以我想要什么仅当我发送 ack 而不是在消费者重启或启动时才应将其标记为重新发送
配置:
@Bean
public org.springframework.amqp.rabbit.connection.Connection mqConnection() {
CloudFactory cloudFactory = new CloudFactory();
Cloud cloud = cloudFactory.getCloud();
return cloud.getServiceConnector("mqservicename", ConnectionFactory.class,
null).createConnection();
}
@Bean
public StatefulRetryOperationsInterceptor interceptor() {
return RetryInterceptorBuilder.stateful().retryOperations(retryTemplate()).recoverer(new RejectAndDontRequeueRecoverer())
.build();
}
@Bean
public SimpleMessageListenerContainer listenerContainer() {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setMessageListener(new MessageListenerAdapter());
container.setAdviceChain(new Advice[] {
interceptor()
});
return container;
}
@Bean
public RetryTemplate retryTemplate(){
Map map=new HashMap<Class<? extends Throwable>, Boolean>();
map.put(CustomException.class, true);
RetryTemplate retryTemplate=new RetryTemplate();
retryTemplate.setRetryPolicy(new SimpleRetryPolicy(3,map));
return retryTemplate;
}
【问题讨论】:
-
您确定要确认消息吗?
-
是的,我是。现在有了 Garys 的评论,我将其关闭并尝试使用上述配置。但它只提供 1 次尝试而不是 3 次
标签: rabbitmq rabbitmq-exchange spring-rabbit