RabbitMQ(高级)笔记

一、生产者可靠性

(1)生产者重连(不建议使用)

复制代码
logging:
  pattern:
    dateformat: MM-dd HH:mm:ss:SSS

spring:
  rabbitmq:
    virtual-host: /hamll
    port: 5672
    host: 192.168.92.136
    username: hmall
    password: 123
    listener:
      simple:
        prefetch: 1
    connection-timeout: 1s
    template:
      retry:
        enabled: true
        initial-interval: 1000ms
        multiplier: 1
        max-attempts: 3

(2)生产者确认

引入日志依赖

复制代码
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </dependency>

二、MQ持久化

(1)持久化介绍

发送100万条消息给队列,需要先在application.yml中取消生产者确认

复制代码
    publisher-confirm-type: none
    publisher-returns: false

没有持久化的测试用例,会出行阻塞的状态:

改为持久化后的测试用例:

(2)最好的持久化方式Lazy Queue

三、消息可靠性

(1)消费者确认

使用auto自动模式

(2)失败重试机制

(3)业务幂等性

四、延迟消息

(1)死信交换机

注意:创建的simple.queue需要Add Dead letter exchange,其他都跟之前创建的操作差不多

监听

复制代码
    @RabbitListener(queues = "dlx.queue")
    public void listenDlxQueue(String msg){
        log.info("dlx.queue消费者收到消息:"+msg);
    }

测试用例

复制代码
    @Test
    void testSendTTLMessage(){

        rabbitTemplate.convertAndSend("simple.direct", "hi", "hello", new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setExpiration("10000");
                return message;
            }
        });
        log.info("消息发送成功!");
    }

(2)延迟消息插件

(3)取消订单

相关推荐
014-code4 分钟前
RabbitMQ 生产端可靠投递(confirm、return、重试)
分布式·消息队列·rabbitmq
Storynone13 分钟前
【踩坑笔记】Geforce RTX5060 显卡对应的 Pytorch 安装
人工智能·pytorch·笔记
014-code13 分钟前
RabbitMQ 消费端幂等实战(重复消息、去重、重放怎么处理)
分布式·消息队列·rabbitmq
jasnet_u21 分钟前
kafka-3.8.0三节点集群(KRaft协议)
分布式·kafka
鸽子一号23 分钟前
c#笔记之lambda表达式和linq
笔记·c#·linq
Xudde.1 小时前
班级作业笔记报告0x05
笔记·学习·安全·web安全
问道飞鱼1 小时前
【分布式技术】分布式对象存储服务RustFS
分布式·对象存储·rustfs
_李小白1 小时前
【OSG学习笔记】Day 24: Texture2D 与 Image
android·笔记·学习
猹叉叉(学习版)1 小时前
【系统分析师_知识点整理】 12.系统设计
笔记·软考·系统设计·系统分析师