spring boot 集成 rabbit mq

第一步引入springboot 依赖
        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency>
第二步添加rabbitmq配置
spring:rabbitmq:host: 127.0.0.1port: 17004username: adminpassword: ******virtual-host: /nonautoexchange: EX_ZY_PROPOSALSTATUSroutingKey: ZY_PROPOSALSTATUSqueue: Q_ZY_PROPOSALSTATUS
第三步添加rabbitmq配置类
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.amqp.core.Queue;
/*** @ClassName RabbitConfig* @Description rabbit mq 配置类* @Author God丶Man* @Date 2022/3/19 11:13* @Version 1.0**/
@Configuration
public class RabbitConfig {@Value("${spring.rabbitmq.exchange}")private String exchange;@Value("${spring.rabbitmq.routingKey}")private String routingKey;@Value("${spring.rabbitmq.queue}")private String queue;@Beanpublic Queue proposalQueue() {return new Queue(queue, true);}@Beanpublic DirectExchange proposalExchange() {return new DirectExchange(exchange, true, false);}@Beanpublic Binding bindingDirect() {return BindingBuilder.bind(proposalQueue()).to(proposalExchange()).with(routingKey);}
}
第四步消息生产者消费者测试类
import cn.hutool.json.JSONUtil;
import com.dh.marketplatform.vehicle.BaseTest;
import org.junit.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;import java.util.HashMap;
import java.util.Map;/*** @ClassName RabbitMqTest* @Description 消息生产者测试类* @Author God丶Man* @Date 2022/3/19 11:31* @Version 1.0**/
public class RabbitMqTest extends BaseTest {@Autowiredprivate RabbitTemplate rabbitTemplate;@Testpublic void testMq() {// 发送消息 商业险Map<String, Object> paramMap = getStringObjectMap();String reqStr = JSONUtil.toJsonStr(paramMap);System.out.println(reqStr);/*** Convert a Java object to an Amqp {@link Message} and send it to a specific exchange* with a specific routing key.** @param exchange the name of the exchange* @param routingKey the routing key* @param message a message to send* @throws AmqpException if there is a problem*/rabbitTemplate.convertAndSend("EX_ZY_PROPOSALSTATUS", "ZY_PROPOSALSTATUS", reqStr);}private Map<String, Object> getStringObjectMap() {Map<String,Object> paramMap = new HashMap<>();paramMap.put("proposalNo","110250020221230000003");paramMap.put("proposalStatus","0");paramMap.put("riskCode","1230");return paramMap;}}
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;import java.util.List;/*** @ClassName RabbitMq* @Description 消息消费者测试类* @Author God丶Man* @Date 2022/3/19 11:33* @Version 1.0**/
@Component
@Slf4j
public class RabbitMqConsumer {@RabbitListener(bindings = @QueueBinding(value = @Queue(value = "${spring.rabbitmq.queue}", autoDelete = "false"),exchange = @Exchange(value = "${spring.rabbitmq.exchange}")))public void messagerevice(String message) {log.info("========接受消息打印: " + message);}}

springboot引入rabbit mq相关推荐

  1. springboot+Rabit实战一:(Rabbit MQ windows 环境搭建)

    一:下载erlang 语言并安装: 地址:http://www.erlang.org/downloads 安装时,是可视化界面一步步安装即可,如果没有配置ERLANG_HOME,则需要配置,并在pat ...

  2. springboot+Rabit实战二:(Rabbit MQ web 界面管理)

    本章基于博主上一篇文章:springboot+Rabit实战一:(Rabbit MQ windows 环境搭建)继续深入,介绍rabbit MQ web界面管理操作 一:先了解Rabbit MQ 中一 ...

  3. Spring Boot:使用Rabbit MQ消息队列

    综合概述 消息队列 消息队列就是一个消息的链表,可以把消息看作一个记录,具有特定的格式以及特定的优先级.对消息队列有写权限的进程可以向消息队列中按照一定的规则添加新消息,对消息队列有读权限的进程则可以 ...

  4. spring-boot 引入xml注入bean

    2019独角兽企业重金招聘Python工程师标准>>> spring-boot 引入xml注入bean 配置 public class TestServiceImpl impleme ...

  5. Rabbit MQ 学习 (一)Window安装Erlang环境

    之前也没有用过Rabbit MQ ,最近正在学习中,记性不好,特意记一下. 百度一下 先得 安装 Erlang 并且 设置环境变量. 在Erlang 官网去下载,那个慢呀... 还好CSDN 里有人提 ...

  6. spring集成mq_使用Spring Integration Java DSL与Rabbit MQ集成

    spring集成mq 我最近参加了在拉斯维加斯举行的2016年Spring大会 ,很幸运地看到了我在软件世界中长期敬佩的一些人. 我亲自遇到了其中的两个人,他们实际上合并了几年前我与Spring In ...

  7. Rabbit MQ windows下安装

    Rabbit MQ 是建立在强大的Erlang OTP平台上,因此安装Rabbit MQ的前提是安装Erlang.通过下面两个连接可以下载安装最新的版本: 下载并安装 Eralng OTP For W ...

  8. springboot引入外部yml配置文件

    本文记录下springboot引入外部yml配置文件 文章目录 概述 本文小结 概述 如果不想把所有的配置都写在application.yml文件中,把它拆分成多个yml文件,并在applicatio ...

  9. Rabbit MQ 配置

    主要介绍Rabbit MQ在Aliyun实例中的安装配置 1.安装erlang, Rabbitmq. 1.1 安装erlang a.执行sudo apt-get update b.执行sudo apt ...

最新文章

  1. 如何实现在H5里调起高德地图APP?(下)
  2. strstr php文档,php字符串函数学习之strstr()
  3. R语言ggplot2可视化:为可视化图像添加多行标题(multi line title)并将多行标题居中对齐(center align)
  4. linux 清空nat,linux 命令iptables -t nat
  5. sublime运行python代码_怎么用sublime运行python
  6. 如何用 Linux 技巧大大提高工作效率?
  7. 【转】java枚举类型ENUM
  8. C语言图形库简单对比及EGE库的安装小手册
  9. 如何运营ASO积分墙用户,aso积分墙是什么意思
  10. USB,蓝牙,以太网,还是WIFI?
  11. 2021年中国全自动棉纱缠绕机市场趋势报告、技术动态创新及2027年市场预测
  12. mac上免费的音频剪辑软件在哪里可以快速下载
  13. Mean-Shift算法
  14. android 标注 比例换算,android APP UI设计图标注、换算
  15. python飞机大战简单的实现
  16. Github Arctic Code Vault 哈哈 自己的项目被存储在北极 1000年
  17. shell python运维脚本_【Python运维】最简单的Python运维脚本
  18. XechWic工作室,视频会议,p2p开发库
  19. 简单介绍一下微信直播
  20. 温德姆酒店集团计划未来三年内在中国开设500家酒店

热门文章

  1. C51模拟PS2键盘(四)
  2. 科普大佬说 | 港大黄凯斌老师带你解锁黑客帝国与6G的关系
  3. Lecture 22
  4. 成为Java顶尖程序员 ,看这9本书就够了
  5. 人是什么?从生物学的角度来说,人就是直立行走无毛动物而已...这是一个多么可怕的世界啊
  6. 毕业五年,终于上车了
  7. 转:R语言在已有图形上面添加一条直线
  8. 不要在极端情绪下处理感情,好吗?
  9. C++ 取整,四舍五入
  10. css使用ttf字体