RabbitMQ基本概念
保证消息持久化
消息到MQ的过程中搞丢,MQ自己搞丢,MQ到消费过程中搞丢。
生产者到RabbitMQ:事务机制和Confirm机制,注意:事务机制和 Confirm 机制是互斥的,两者不能共存,会导致 RabbitMQ 报错。
RabbitMQ自身:持久化、集群、普通模式、镜像模式。
RabbitMQ到消费者:关闭RabbitMQ自动ACK
springboot配置
引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
application.yml文件
server:
port: 8001
spring:
application:
name: myrabbitMqDemo-provider
#配置rabbitMq 服务器
rabbitmq:
host: 192.168.232.134
port: 5672
username: guest
password: guest
#虚拟host 可以不设置,使用server默认host
#virtual-host: tmp
#确认消息已发送到交换机(Exchange) 发送确认
#publisher-confirms: true
publisher-confirm-type: correlated
#确认消息已发送到队列(Queue) 发送回调
publisher-returns: true
listener:
simple:
#程序中设置:rabbitTemplate.setMandatory(true);
acknowledge-mode: manual
#并发消费者初始化值
concurrency: 10
#并发消费者的最大值
max-concurrency: 20
#每个消费者每次监听时可拉取处理的消息数量
prefetch: 1