zoukankan      html  css  js  c++  java
  • springboot配置rabbitmq

    一.消息生成者

    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单个消费者参数配置,限流参数配置

     
  • 相关阅读:
    oracle数据库使用PL/sql导入excel数据
    http协议详解之响应报文 3
    http详解之post 2
    http协议详解1
    tomcat配置https协议
    linux服务端导入oracle数据库.sql脚本
    fiddler查看http压缩格式传输的报文
    SurfaceView绘制录音波形图
    android 蓝牙SPP协议通信
    好用的Android屏幕适配
  • 原文地址:https://www.cnblogs.com/djq-jone/p/13175482.html
Copyright © 2011-2022 走看看