rabbitMq处理消息报 PublisherCallbackChannel is closed 异常
在java springboot 项目中 利用@RabbitListener 监听处理消息时 消息处理成功,但偶尔报PublisherCallbackChannel is closed 异常 。
处理消息代码如下:
@RabbitListener(queues = {CommonConstant.PRODUCT_SEARCH_QUEUE}) public void receiverProductSearchQueue(Message message, Channel channel) throws IOException { log.info("开始消费:" + new String(message.getBody())); try { long productSkuId = Long.parseLong(new String(message.getBody())); ResultVo resultVo = esSearchService.saveProductToElasticSearch(productSkuId); if (resultVo.getCode() == CommonConstant.SUCCESS) { log.info("消费成功:" + resultVo.getMsg()); } else { log.info("消费失败-------------" + message); } } catch (Exception ex) { log.error(ex.toString() + "-------------" + message); } finally { channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); } }
最后修改 yml配置文件问题解决,配置如下:
#消息配置 rabbitmq: host: simba-test-mq port: 5672 username: simba password: simba virtual-host: / template: routing-key: product_search exchange: product_search_exchange mandatory: true #publisher-confirms: true publisher-returns: true queue-name: product_search_queue listener: simple: acknowledge-mode: manual #消息手动确认 concurrency: 4 #消费者数量 max-concurrency: 50 #消费者最大数量 prefetch: 1 #消费者每次从队列中取几个消息 default-requeue-rejected: true #消息消费失败后,重新进入消费队列中 retry: initial-interval: 1000 #1秒后重试 enabled: true #启用发布重试 max-attempts: 3 #传递消息的最大尝试次数 max-interval: 10000 #尝试的最大时间间隔 multiplier: 1.0 #应用于先前传递重试时间间隔的乘数
本文来自博客园,作者:清玄-2012,转载请注明原文链接:https://www.cnblogs.com/happy-tears/p/15628234.html