不存在交换时,我无法捕获到异常。
它只是打印到错误日志:
Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'mc_topic1' in vhost 'mc_vhost', class-id=60, method-id=40).
我的代码:
rabbitTemplate.convertAndSend(producerBo.getExchange(), producerBo.getRoutingKey(), JSON.toJSONString(producerBo.getData()), message -> {
MessageProperties messageProperties = message.getMessageProperties();
messageProperties.setDeliveryMode(MessageDeliveryMode.fromInt(Optional.ofNullable(producerBo.getDeliveryMode()).orElse(2)));
if (Objects.nonNull(producerBo.getExpiration())) {
messageProperties.setExpiration(String.valueOf(producerBo.getExpiration()));
}
return message;
});