一.消息生成者
1.1消息生成者配置
1.2 消息发送端代码
1.3 创建交换机,队列,并建立关系
二.消费者
2.1消费者
三.限流配置
3.1配置文件
#在单个请求中处理的消息个数,他应该大于等于事务数量(unack的最大数量) spring.rabbitmq.listener.simple.prefetch=2 #在@RabbitListener(queues = { HighDeviceMessage.QUEUE_NAME },concurrency = "${spring.rabbitmq.highdevice.concurrency}")配置的占位符配置 spring.rabbitmq.highdevice.concurrency=2-5
3.2消费者配置
@Component public class HighDeviceMessageHandler { // @RabbitListener(queues = { HighDeviceMessage.QUEUE_NAME },ackMode ="MANUAL",concurrency = "1-10") @RabbitListener(queues = { HighDeviceMessage.QUEUE_NAME },ackMode ="MANUAL",concurrency = "${spring.rabbitmq.highdevice.concurrency}") public void handle(String msgStr, Channel channel,@Headers Map<String,Object> headers) { try { log.info("休息3秒"); log.info("handle HighDeviceMessage:{}---",msgStr); TimeUnit.SECONDS.sleep(3); long deliveryTag = (Long)headers.get(AmqpHeaders.DELIVERY_TAG); //手工ack channel.basicAck(deliveryTag,true); } catch (Exception e) { log.error("handle HighDeviceMessage err", e); } } }
2020年6月23日16:58:05 -- 更新mq单个消费者参数配置,限流参数配置