1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| @Configuration public class RabbitConfig implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnCallback {
@Autowired private RabbitTemplate rabbitTemplate;
private static final Logger logger = LoggerFactory.getLogger(RabbitConfig.class);
@PostConstruct public void initRabbitTemplate() { rabbitTemplate.setConfirmCallback(this); rabbitTemplate.setReturnCallback(this); }
@Override public void confirm(CorrelationData correlationData, boolean ack, String cause) { if (ack) { logger.info("{}消息成功到达交换机",correlationData.getId()); } else { logger.info("消息发送到Exchange失败, {}, cause: {}", correlationData, cause); } }
@Override public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) { logger.error("消息从Exchange路由到Queue失败: exchange: {}, route: {}, replyCode: {}, replyText: {}, message: {}", exchange, routingKey, replyCode, replyText, message); }
}
|