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 #卷组名字,将…...
现代企业架构框架——应用架构
现代企业架构框架——应用架构。 现代企业架构中的应用架构是指企业在构建和维护应用系统时所采用的一种架构框架。应用架构旨在实现应用系统的可扩展性、灵活性、可维护性和可重用性,以满足企业在数字化时代对应用系统的快速交付和持续创新的需求。下面将详细介绍应用架构的…...
Intv_AI_MK11 快速集成指南:与Dify平台构建可视化AI智能体工作流
Intv_AI_MK11 快速集成指南:与Dify平台构建可视化AI智能体工作流 1. 引言:当专业模型遇上低代码平台 最近遇到不少开发者朋友都在问同一个问题:手上有不错的AI模型,但怎么快速把它变成可交互的智能应用?这正是我们今…...
B站缓存视频无法播放?m4s-converter让您的收藏永不消失
B站缓存视频无法播放?m4s-converter让您的收藏永不消失 【免费下载链接】m4s-converter 一个跨平台小工具,将bilibili缓存的m4s格式音视频文件合并成mp4 项目地址: https://gitcode.com/gh_mirrors/m4/m4s-converter 在数字内容爆炸的时代&#x…...
DETR目标检测实战:从零搭建与核心模块解析
1. DETR目标检测模型初探 第一次接触DETR(Detection Transformer)时,我被它简洁优雅的设计深深吸引。传统目标检测模型如Faster R-CNN、YOLO等都需要复杂的锚框设计和后处理步骤,而DETR直接用Transformer实现了端到端的目标检测,完全摒弃了这…...
GaussianSplats3D的WebXR集成:构建VR/AR沉浸式体验
GaussianSplats3D的WebXR集成:构建VR/AR沉浸式体验 【免费下载链接】GaussianSplats3D Three.js-based implementation of 3D Gaussian splatting 项目地址: https://gitcode.com/gh_mirrors/ga/GaussianSplats3D GaussianSplats3D是基于Three.js的3D高斯 sp…...
C语言条件编译三种方式及第一种方式的格式、作用与示例
预处理程序具备支持条件编译的特性,借着该特性能够依据不一样的条件,对程序当中不同的部分实施编译操作,由此去生成与之相对应的目标代码,而此情况对程序的移植以及调试是有着帮助作用的。条件编译总共存在着三种方式,…...
UVM TLM analysis_port的write函数:从端口声明到数据处理的完整链路解析
1. UVM TLM analysis_port基础概念 在UVM验证环境中,TLM(Transaction Level Modeling)通信机制是组件间数据交互的核心方式。analysis_port作为TLM接口的一种特殊类型,主要用于实现单向、多播的数据传输。与传统的TLM端口不同&…...
详细教程:Ubuntu服务器部署万象熔炉,支持高清图像生成
详细教程:Ubuntu服务器部署万象熔炉,支持高清图像生成 1. 环境准备与系统配置 在开始部署万象熔炉之前,我们需要确保服务器环境满足基本要求。本教程以Ubuntu 20.04 LTS为例,但同样适用于其他主流Linux发行版。 1.1 系统要求检…...
生成式AI伦理治理不能再等下一版政策:SITS2026圆桌强制推荐——所有L3以上AI系统须嵌入实时伦理哨兵模块(开源SDK已上线GitHub Trending Top 1)
第一章:SITS2026圆桌:生成式AI应用伦理 2026奇点智能技术大会(https://ml-summit.org) 伦理治理的实践锚点 在SITS2026圆桌讨论中,来自欧盟AI办公室、中国信通院及OpenAI伦理委员会的代表共同提出:生成式AI的伦理落地不能依赖抽…...
影响APP增长的13个ASO核心要素(2026最新版)
ASO是APP自然增长的生命线,但其复杂的规则与多变的算法常让运营者束手无策。2026年,应用商店对“质量度”与“用户匹配度”的考核愈发严格,粗放型的优化手段难以奏效。基于最新市场动态与业务实战,我们将ASO拆解为产品契合、关键词…...
如何快速上手Remmina:面向新手的10个简单设置技巧
如何快速上手Remmina:面向新手的10个简单设置技巧 【免费下载链接】Remmina Mirror of https://gitlab.com/Remmina/Remmina The GTK Remmina Remote Desktop Client 项目地址: https://gitcode.com/gh_mirrors/re/Remmina Remmina是一款功能强大的GTK远程桌…...
