SpringBoot整合rabbitmq-直连队列,没有交换机(一)
说明:本文章只是springboot和rabbitmq的直连整合,只使用队列生产和消费消息,最简单整合!
工程图:

A.总体pom.xml
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><artifactId>spring-boot-starter-parent</artifactId> <!-- 被继承的父项目的构件标识符 --><groupId>org.springframework.boot</groupId> <!-- 被继承的父项目的全球唯一标识符 --><version>2.2.2.RELEASE</version> <!-- 被继承的父项目的版本 --><relativePath/> <!-- lookup parent from repository --></parent><groupId>RabbitMqSpringbootDemo</groupId><artifactId>RabbitMqSpringbootDemo</artifactId><version>1.0-SNAPSHOT</version><packaging>pom</packaging><modules><module>MqCustomer</module><module>MqProducer</module></modules><name>RabbitMqSpringbootDemo Maven Webapp</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><dependencies></dependencies><build><finalName>RabbitMqSpringbootDemo</finalName><pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --><plugins><plugin><artifactId>maven-clean-plugin</artifactId><version>3.1.0</version></plugin><!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --><plugin><artifactId>maven-resources-plugin</artifactId><version>3.0.2</version></plugin><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.8.0</version></plugin><plugin><artifactId>maven-surefire-plugin</artifactId><version>2.22.1</version></plugin><plugin><artifactId>maven-war-plugin</artifactId><version>3.2.2</version></plugin><plugin><artifactId>maven-install-plugin</artifactId><version>2.5.2</version></plugin><plugin><artifactId>maven-deploy-plugin</artifactId><version>2.8.2</version></plugin></plugins></pluginManagement></build>
</project>
B.生产者:MyProducer
1.pom.xml
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>RabbitMqSpringbootDemo</artifactId><groupId>RabbitMqSpringbootDemo</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>MqProducer</artifactId><packaging>jar</packaging><name>MqProducer Maven Webapp</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><dependencies><!--spring boot核心--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><!--spring boot 测试--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!--springmvc web--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--开发环境调试--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional></dependency><!--amqp 支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.78</version></dependency><!-- commons-lang3 --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.4</version></dependency><!--lombok--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.16.10</version></dependency></dependencies><build><finalName>MqProducer</finalName><pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --><plugins><plugin><artifactId>maven-clean-plugin</artifactId><version>3.1.0</version></plugin><!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --><plugin><artifactId>maven-resources-plugin</artifactId><version>3.0.2</version></plugin><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.8.0</version></plugin><plugin><artifactId>maven-surefire-plugin</artifactId><version>2.22.1</version></plugin><plugin><artifactId>maven-war-plugin</artifactId><version>3.2.2</version></plugin><plugin><artifactId>maven-install-plugin</artifactId><version>2.5.2</version></plugin><plugin><artifactId>maven-deploy-plugin</artifactId><version>2.8.2</version></plugin></plugins></pluginManagement></build>
</project>
2.application.yml
server:port: 8080
spring:rabbitmq:port: 5672host: 192.168.18.145username: adminpassword: adminvirtual-host: /
3.AppP
package com.dev;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;/*** 类名称:** @author lqw* @date 2024年02月27日 14:20*/
@SpringBootApplication
public class AppP {public static void main(String[] args) {SpringApplication.run(AppP.class);}
}
4.OnlyQueueRabbitConfig
package com.dev.config;import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** 类名称:** @author lqw* @date 2024年02月28日 10:40*/
@Configuration
public class OnlyQueueRabbitConfig {/*** 队列* @return onlyQueue队列名称 true 持久化*/@Beanpublic Queue directOnlyQueue(){return new Queue("onlyQueue",true);}}
5.OnlyQueueController
package com.dev.controller;import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** 类名称:直接交换机 消息生产者** @author lqw* @date 2024年02月27日 14:47*/
@Slf4j
@RestController
@RequestMapping("onlyQueue")
public class OnlyQueueController {@AutowiredRabbitTemplate rabbitTemplate; //使用RabbitTemplate,这提供了接收/发送等等方法/*** Direct测试* @return*/@GetMapping("/sendMessageByOnlyQueue")public String sendMessageByOnlyQueue() {rabbitTemplate.convertAndSend("", "onlyQueue", "你好,Queue!我是直连队列发送的消息!");return "ok";}}
C.消费者:MqCustomer
1.pom.xml
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>RabbitMqSpringbootDemo</artifactId><groupId>RabbitMqSpringbootDemo</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>MqCustomer</artifactId><packaging>jar</packaging><name>MqCustomer Maven Webapp</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><dependencies><!--spring boot核心--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><!--spring boot 测试--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!--springmvc web--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--开发环境调试--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional></dependency><!--amqp 支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency><!-- commons-lang3 --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.4</version></dependency><!--lombok--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.16.10</version></dependency></dependencies><build><finalName>MqCustomer</finalName><pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --><plugins><plugin><artifactId>maven-clean-plugin</artifactId><version>3.1.0</version></plugin><!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --><plugin><artifactId>maven-resources-plugin</artifactId><version>3.0.2</version></plugin><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.8.0</version></plugin><plugin><artifactId>maven-surefire-plugin</artifactId><version>2.22.1</version></plugin><plugin><artifactId>maven-war-plugin</artifactId><version>3.2.2</version></plugin><plugin><artifactId>maven-install-plugin</artifactId><version>2.5.2</version></plugin><plugin><artifactId>maven-deploy-plugin</artifactId><version>2.8.2</version></plugin></plugins></pluginManagement></build>
</project>
2.application.yml
server:port: 8081spring:rabbitmq:port: 5672host: 192.168.18.145username: adminpassword: admin
3.AppC
package cn.ct;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;/*** 类名称:** @author lqw* @date 2024年02月27日 14:20*/
@SpringBootApplication
public class AppC {public static void main(String[] args) {SpringApplication.run(AppC.class);}
}
4.OnlyQueueRabbitListener
package cn.ct.listeners;import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;/*** 类名称:消息消费者* 直连* @author lqw* @date 2024年02月27日 14:58*/
@Component
public class OnlyQueueRabbitListener {@RabbitListener(queues = "onlyQueue")@RabbitHandlerpublic void process(String hello) {System.out.println("Rabbitmq : " + hello);}}
总结:这个是mq消息的最简单的使用,只使用队列!
相关文章:
SpringBoot整合rabbitmq-直连队列,没有交换机(一)
说明:本文章只是springboot和rabbitmq的直连整合,只使用队列生产和消费消息,最简单整合! 工程图: A.总体pom.xml <?xml version"1.0" encoding"UTF-8"?><project xmlns"http://…...
CUDA C:查看GPU设备信息
相关阅读 CUDA Chttps://blog.csdn.net/weixin_45791458/category_12530616.html?spm1001.2014.3001.5482 了解自己设备的性能是很有必要的,为此CUDA 运行时(runtime)API给用户也提供了一些查询设备信息的函数,下面的函数用于查看GPU设备的一切信息。 …...
深度学习如何入门?——从“小白”到“大牛”的深度学习之旅
大家好,今天我要和大家分享的主题是“深度学习如何入门”。深度学习作为人工智能领域的重要分支,已经取得了许多令人瞩目的成果。然而,对于初学者来说,深度学习可能显得有些神秘和难以入手。那么,如何才能快速入门深度…...
编译 qsqlmysql.dll QMYSQL driver not loaded
Qt 连接MySQL数据库,没有匹配的qsqlmysql.dll, 需要我们跟进自己Mysql 以及QT版本自行编译的。异常如下图: 安装环境为 VS2019 Qt5.12.12(msvc2017_64、以及源码) 我的安装地址:D:\Qt\Qt5.12.12 Mysql 8.1.0 默认安…...
Android日历提醒增删改查事件、添加天数不对问题
Android日历提醒是非常好的提醒功能,笔者在做的过程中,遇到的一些问题,现整理出来,以供参考。 一、申请日历的读写权限 <uses-permission android:name"android.permission.WRITE_CALENDAR" /> <uses-permiss…...
【力扣hot100】刷题笔记Day15
前言 今天要刷的是图论,还没学过,先看看《代码随想录》这部分的基础 深搜DFS理论基础 深搜三部曲 确认递归函数、参数确认终止条件处理目前搜索节点出发的路径 代码框架 void dfs(参数) {if (终止条件) {存放结果;return;}for (选择:本节点…...
vue-显示数据
v-text和v-html专门用来展示数据, 其作用和插值表达式类似。v-text和v-html可以避免插值闪烁问题. 当网速比较慢时, 使用{{}}来展示数据, 有可能会产生插值闪烁问题。 插值闪烁: 在数据未加载完成时,页面会显示出原始的{{}}, 过一会才会展示正常数据.语法…...
kali linux常用命令
1. 网络扫描 功能:网络扫描是用来发现网络中的设备、服务和开放端口的过程。 命令:nmap 例子:nmap -sP 192.168.1.0/24 这个命令使用 Nmap 进行网络扫描,列出 192.168.1.0/24 网段中的所有活跃主机。 2. 密码破解 功能…...
HTML5:七天学会基础动画网页4
backgorund-size 值与说明 length(单位像素):设置背景图片高度和宽度,第一个值设置宽度,第二个值设置高度,如果只给出一个值,第二个是设置为auto。 percentage(百分比):以父元素的百分比来设置背景图像的宽度和高度,…...
Web安全之接口鉴权
目录 接口鉴权定义 为什么会有cookie还有session还有token这种技术的存在?...
shardingsphere 集成springboot【水平分表】
创建sharding_sphere数据库 在数据库中创建两张表,t_order_1和t_order_2 分片规则:如果订单编号是偶数添加到t_order_1,如果是奇数添加到t_order_2 创建实体类 public class Order { private Integer id; private Integer orderType; private Int…...
GO 的 Web 开发系列(六)—— 遍历路径下的文件
文件 IO 处理是程序的基础功能,WEB 程序中通过文件 IO 实现附件的上传与下载。在 GO 中,有多种方式可以遍历文件目录,获取文件路径,本文从使用层面上论述这些函数。 预先准备一个包含子目录的目录,用于遍历测试&#…...
Flutter 处理异步操作并根据异步操作状态动态构建界面的方法FutureBuilder
概述 当界面的内容需要依靠网络请求的数据,就需要处理苦恼的,状态是空,非空的逻辑了,不然页面构建可能会报错,而FutureBuilder提供了一个非常好的解决方法,直接看代码 代码 异步操作函数 即网络请求函数…...
Git教程-Git的基本使用
Git是一个强大的分布式版本控制系统,它不仅用于跟踪代码的变化,还能够协调多个开发者之间的工作。在软件开发过程中,Git被广泛应用于协作开发、版本管理和代码追踪等方面。以下是一个详细的Git教程,我们将深入探讨Git的基本概念和…...
Java解决长度为K子的数组中的的最大和
Java解决长度为K子的数组中的的最大和 01 题目 给你一个整数数组 nums 和一个整数 k 。请你从 nums 中满足下述条件的全部子数组中找出最大子数组和: 子数组的长度是 k,且子数组中的所有元素 各不相同 。 返回满足题面要求的最大子数组和。如果不存在子…...
【手机端测试】adb基础命令
一、什么是adb adb(Android Debug Bridge)是android sdk的一个工具 adb是用来连接安卓手机和PC端的桥梁,要有adb作为二者之间的维系,才能让用户在电脑上对手机进行全面的操作。 Android的初衷是用adb这样的一个工具来协助开发人…...
【数据结构】深入探讨二叉树的遍历和分治思想(一)
🚩纸上得来终觉浅, 绝知此事要躬行。 🌟主页:June-Frost 🚀专栏:数据结构 🔥该文章主要讲述二叉树的递归结构及分治算法的思想。 目录: 🌍前言:🌍…...
jQuery AJAX get() 和 post() 方法—— W3school 详解 简单易懂(二十四)
jQuery get() 和 post() 方法用于通过 HTTP GET 或 POST 请求从服务器请求数据。 HTTP 请求:GET vs. POST 两种在客户端和服务器端进行请求-响应的常用方法是:GET 和 POST。 GET - 从指定的资源请求数据POST - 向指定的资源提交要处理的数据 GET 基本…...
Linux中如何进行LVM逻辑卷扩容?
#注意:如果lv所在的vg有空间直接扩容就ok了! 1.创建pv pvcreate /dev/sdb 执行以上命令得到以下内容: Physical volume "/dev/sdb" successfully created. 2.直接vgextend扩容 vgextend vg1 /dev/sdb #卷组名字,将…...
现代企业架构框架——应用架构
现代企业架构框架——应用架构。 现代企业架构中的应用架构是指企业在构建和维护应用系统时所采用的一种架构框架。应用架构旨在实现应用系统的可扩展性、灵活性、可维护性和可重用性,以满足企业在数字化时代对应用系统的快速交付和持续创新的需求。下面将详细介绍应用架构的…...
AI-调查研究-01-正念冥想有用吗?对健康的影响及科学指南
点一下关注吧!!!非常感谢!!持续更新!!! 🚀 AI篇持续更新中!(长期更新) 目前2025年06月05日更新到: AI炼丹日志-28 - Aud…...
DeepSeek 赋能智慧能源:微电网优化调度的智能革新路径
目录 一、智慧能源微电网优化调度概述1.1 智慧能源微电网概念1.2 优化调度的重要性1.3 目前面临的挑战 二、DeepSeek 技术探秘2.1 DeepSeek 技术原理2.2 DeepSeek 独特优势2.3 DeepSeek 在 AI 领域地位 三、DeepSeek 在微电网优化调度中的应用剖析3.1 数据处理与分析3.2 预测与…...
OkHttp 中实现断点续传 demo
在 OkHttp 中实现断点续传主要通过以下步骤完成,核心是利用 HTTP 协议的 Range 请求头指定下载范围: 实现原理 Range 请求头:向服务器请求文件的特定字节范围(如 Range: bytes1024-) 本地文件记录:保存已…...
基于Docker Compose部署Java微服务项目
一. 创建根项目 根项目(父项目)主要用于依赖管理 一些需要注意的点: 打包方式需要为 pom<modules>里需要注册子模块不要引入maven的打包插件,否则打包时会出问题 <?xml version"1.0" encoding"UTF-8…...
GitHub 趋势日报 (2025年06月08日)
📊 由 TrendForge 系统生成 | 🌐 https://trendforge.devlive.org/ 🌐 本日报中的项目描述已自动翻译为中文 📈 今日获星趋势图 今日获星趋势图 884 cognee 566 dify 414 HumanSystemOptimization 414 omni-tools 321 note-gen …...
前端开发面试题总结-JavaScript篇(一)
文章目录 JavaScript高频问答一、作用域与闭包1.什么是闭包(Closure)?闭包有什么应用场景和潜在问题?2.解释 JavaScript 的作用域链(Scope Chain) 二、原型与继承3.原型链是什么?如何实现继承&a…...
图表类系列各种样式PPT模版分享
图标图表系列PPT模版,柱状图PPT模版,线状图PPT模版,折线图PPT模版,饼状图PPT模版,雷达图PPT模版,树状图PPT模版 图表类系列各种样式PPT模版分享:图表系列PPT模板https://pan.quark.cn/s/20d40aa…...
Reasoning over Uncertain Text by Generative Large Language Models
https://ojs.aaai.org/index.php/AAAI/article/view/34674/36829https://ojs.aaai.org/index.php/AAAI/article/view/34674/36829 1. 概述 文本中的不确定性在许多语境中传达,从日常对话到特定领域的文档(例如医学文档)(Heritage 2013;Landmark、Gulbrandsen 和 Svenevei…...
Java求职者面试指南:计算机基础与源码原理深度解析
Java求职者面试指南:计算机基础与源码原理深度解析 第一轮提问:基础概念问题 1. 请解释什么是进程和线程的区别? 面试官:进程是程序的一次执行过程,是系统进行资源分配和调度的基本单位;而线程是进程中的…...
STM32HAL库USART源代码解析及应用
STM32HAL库USART源代码解析 前言STM32CubeIDE配置串口USART和UART的选择使用模式参数设置GPIO配置DMA配置中断配置硬件流控制使能生成代码解析和使用方法串口初始化__UART_HandleTypeDef结构体浅析HAL库代码实际使用方法使用轮询方式发送使用轮询方式接收使用中断方式发送使用中…...
