春季AMQP异常

时间:2019-07-09 09:29:57

标签: spring-amqp

不存在交换时,我无法捕获到异常。

它只是打印到错误日志:

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;
        });

0 个答案:

没有答案