SpringBoot 成Rabbitmq的疑惑记录

1、手动确认机制实现 ChannelAwareMessageListener 接口, 和使用注解@RabbitListener并在配置文件添加spring.rabbitmq.listener.direct.acknowledge-mode=manual, 两种方式有什么差异吗?

   前者可以精确到特定的message,后者是针对全局。
 
2、message.getMessageProperties().getCorrelationIdString()获取你添加的correlationDataId失败
  Rabbitmq在2.0版本中删除了 the byte[] version of correlation id,目前可以通过如下方式进行设置
MessageProperties properties = new MessageProperties();
                properties.setCorrelationId(messageId);

                correlationData.setId(messageId);

                this.rabbitTemplate().convertAndSend(exchangeName, routingKeyName,
                        MessageBuilder.withBody(objectMapper.writeValueAsBytes(content)).andProperties(properties).build(), correlationData);

通过message.getMessageProperties().getCorrelationIdString()方式进行获取上面的方法获取correlationDataId。

3、如何设置消息持久化

  我们在设置queue和exchange持久化后,通过convertAndSend()方法发送的message默认是持久化的,具体点击方法看源码的时候会发现如下注释:

Message persistent: Set the deliveryMode of the message to 2 and the consumer can continue to consume
     * the messages after persistence after restarting;
     * Use convertAndSend to send a message. The message is persistent by default. The following is the source code:
     * new MessageProperties() --> DEFAULT_DELIVERY_MODE = MessageDeliveryMode.PERSISTENT --> deliveryMode = 2;

本内容持续更新,待续。。。

原文地址:https://www.cnblogs.com/daishoucheng/p/11976446.html