当前位置: 首页 > news >正文

rabbitmq在微服务中配置监听开关

  1. 监听文件类
import cn.hutool.json.JSONObject;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import jnpf.util.JsonUtil;
import jzy.model.mom.EventMessageMom;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import java.io.IOException;@Component
@ConditionalOnProperty(name = "spring.rabbitmq.enable", havingValue = "true", matchIfMissing = true)
public class MultiExchangeMessageListener{private static final Logger logger = LoggerFactory.getLogger(MultiExchangeMessageListener.class);@Autowiredprivate IdempotentMessageProcessor idempotentProcessor;@Autowiredprivate RabbitTemplate rabbitTemplate;/*** 监听来自多个交换机的消息*/// 声明 Direct 交换机、队列,并绑定路由键@RabbitListener(bindings = @QueueBinding(value = @Queue(name = "order.queue", durable = "true"),    // 队列exchange = @Exchange(name = "20250917test1", type = ExchangeTypes.FANOUT) // 交换机))public void handleMessage(Message message) throws IOException {String messageId = message.getMessageProperties().getMessageId();String exchange = message.getMessageProperties().getReceivedExchange();long deliveryTag = message.getMessageProperties().getDeliveryTag();}
  1. 配置文件:在yml里配置具体开关的属性,配置rabbitMq启用开关,false为关闭,true为启用.
  spring:rabbitmq:addresses: 127.0.0.1:5672username: guestpassword: guestvirtual-host: /connection-timeout: 15000#配置rabbitMq启用开关enable: truelistener:simple:acknowledge-mode: manualconcurrency: 15max-concurrency: 20
http://www.dtcms.com/a/506852.html

相关文章:

  • 下一代时序数据库标杆:Apache IoTDB架构演进与AIoT时代的数据战略
  • k8s中的控制器
  • Blender入门学习02
  • 动态规划的“数学之魂”:从DP推演到质因数分解——巧解「只有两个键的键盘」
  • Blender入门学习01
  • 网站开发word文档精品简历模板网站
  • WrenAI:企业级AI数据分析平台技术解析
  • 【Processing】椭圆眼珠鼠标跟随
  • 工业显示器在矿用挖掘机中的应用
  • 济南企业网站开发网站建设域名
  • 【深度学习计算机视觉】14:实战Kaggle比赛:狗的品种识别(ImageNet Dogs)
  • 基于k8s的Python的分布式深度学习训练平台搭建简单实践
  • 网站服务器地址在哪里看前端工程师是做网站吗
  • 基于SpringBoot的环保行为记录与社区互动平台(Vue+MySQL)
  • 洛谷 P3392 涂条纹-普及-
  • 【 柒个贰航空旅游-注册安全分析报告-无验证方式导致安全隐患】
  • CentOS 7 安装 MySQL 8
  • Java 数据类型分类
  • 定制高端网站建设设计上传网站图片不显示
  • 无人机路径规划与定位技术原理及实现详解
  • 自己做公司网站适用于手机的网站怎么建设
  • 解决前端多标签页通信:BroadcastChannel
  • [css] border 渐变
  • 前端错误监控实践:Sentry 在 Vite + Vue 项目中的配置与原理详解
  • Marin说PCB之GMSL2网络中AC电容前端控制100欧姆和不做差分100欧姆的区别?
  • Oracle 数据库 Schema 备份与导入全攻略
  • PySide6 使用搜索引擎搜索 多类实现
  • 东莞市外贸网站建设公司自己做投票的网站
  • 网站建设的基础服务器专业建站公司的业务内容
  • 【iOS】KVC 与 KVO 的基本了解与使用