zoukankan      html  css  js  c++  java
  • 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;

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

  • 相关阅读:
    Java数据结构学习Day2_Java基础排序算法
    Java数据结构学习Day1_队列_用数组模拟队列以及环形队列
    Java数据结构学习Day1_稀疏数组
    系统结构实践第七次作业——23组
    第04组 Alpha事后诸葛亮
    第04组 Alpha冲刺(4/4)
    第04组 Alpha冲刺(3/4)
    第04组 Alpha冲刺(2/4)
    第04组 Alpha冲刺(1/4)
    第四组团队git现场编程实战
  • 原文地址:https://www.cnblogs.com/daishoucheng/p/11976446.html
Copyright © 2011-2022 走看看