做网站学/关键洞察力
上一篇已经讲述了实现死信队列的rabbitMQ服务配置,可以点击: RabbitMQ的延迟队列实现(笔记一)
目录
- 搭建一个新的springboot项目
- 模仿订单延迟支付过期操作
- 启动项目进行测试
搭建一个新的springboot项目
1.相关核心依赖如下
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!--mq依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency><!-- lombok 依赖 --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency>
2.配置文件如下
server:port: 8080spring:#MQ配置rabbitmq:host: ipport: 5673username: rootpassword: root+12345678
3.目录结构
模仿订单延迟支付过期操作
1.创建OrderMqConstant.java,设定常量,代码如下
package com.example.aboutrabbit.constant;
/*** @description 订单队列常量* @author lxh* @time 2024/2/7 17:05*/
public interface OrderMqConstant {/***交换机*/String exchange = "order-event-exchange";/*** 队列*/String orderQueue = "order.delay.queue";/*** 路由*/String orderDelayRouting = "order.delay.routing";
}
2.创建OrderDelayConfig.java,配置绑定
package com.example.aboutrabbit.config;import com.example.aboutrabbit.constant.OrderMqConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import java.util.HashMap;
import java.util.Map;/*** @author lxh* @description 配置绑定* @time 2024/2/7 17:15**/
@Configuration
public class OrderDelayConfig {/*** 延时队列交换机* 注意这里的交换机类型:CustomExchange*/@Beanpublic CustomExchange maliceDelayExchange() {Map<String, Object> args = new HashMap<>();args.put("x-delayed-type", "direct");// 属性参数 交换机名称 交换机类型 是否持久化 是否自动删除 配置参数return new CustomExchange(OrderMqConstant.exchange, "x-delayed-message", true, false, args);}/*** 延时队列*/@Beanpublic Queue maliceDelayQueue() {// 属性参数 队列名称 是否持久化return new Queue(OrderMqConstant.orderQueue, true);}/*** 给延时队列绑定交换机*/@Beanpublic Binding maliceDelayBinding() {return BindingBuilder.bind(maliceDelayQueue()).to(maliceDelayExchange()).with(OrderMqConstant.orderDelayRouting).noargs();}
}
3、创建 OrderMQReceiver.java监听过期的消息
package com.example.aboutrabbit.config;import com.example.aboutrabbit.constant.OrderMqConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;import java.text.SimpleDateFormat;
import java.util.Date;/*** @author lxh* @description 接收过期订单* @time 2024/2/7 17:21**/
@Component
@Slf4j
public class OrderMQReceiver {@RabbitListener(queues = OrderMqConstant.orderQueue)public void onDeadMessage(String infoId) {SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");log.info("收到头框过期时间:{},消息是:{}", sdf.format(new Date()), infoId);}
}
4.分别创建MQService.java和MQServiceImpl.java,处理消息发送
package com.example.aboutrabbit.service;
/*** @description MQ发消息服务* @author lxh* @time 2024/2/7 17:26*/
public interface MQService {/*** 发送或加队列* @param orderId 订单主键* @param time 毫秒*/void sendOrderAddInfo(Long orderId, Integer time);
}
package com.example.aboutrabbit.service.impl;import com.example.aboutrabbit.constant.OrderMqConstant;
import com.example.aboutrabbit.service.MQService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.text.SimpleDateFormat;
import java.util.Date;/*** @author lxh* @description MQ发消息服务实现* @time 2024/2/7 17:26**/
@Slf4j
@Service
public class MQServiceImpl implements MQService {@Autowiredprivate RabbitTemplate rabbitTemplate;/*** 发送或加队列* @param orderId 订单主键* @param time 毫秒*/@Overridepublic void sendOrderAddInfo(Long orderId, Integer time) {SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");log.info("过期队列添加|添加时间:{},内容是:{},过期毫秒数:{}",sdf.format(new Date()),orderId, time);rabbitTemplate.convertAndSend(OrderMqConstant.exchange, OrderMqConstant.orderDelayRouting,orderId,message -> {message.getMessageProperties().setDelay(time);return message;});}
}
5.创建控制层进行测试TestController.java
package com.example.aboutrabbit.controller;import com.example.aboutrabbit.service.MQService;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;/*** @author lxh* @description 测试* @time 2024/2/7 17:36**/
@RestController
@RequestMapping("/test")
public class TestController {@Autowiredprivate MQService mqService;@GetMapping("/send")public String list(@RequestParam Long orderId,@RequestParam Integer fenTime) {//默认Integer time = fenTime * 60 * 1000;mqService.sendOrderAddInfo(orderId, time);return "success";}
}
6.全部结构展示
启动项目进行测试
1.示例:localhost:8080/test/send?orderId=1&fenTime=1
订单id为1的延迟一分钟过期,如下
2.查看日志
相关文章:

RabbitMQ的延迟队列实现[死信队列](笔记二)
上一篇已经讲述了实现死信队列的rabbitMQ服务配置,可以点击: RabbitMQ的延迟队列实现(笔记一) 目录 搭建一个新的springboot项目模仿订单延迟支付过期操作启动项目进行测试 搭建一个新的springboot项目 1.相关核心依赖如下 <dependency><groupId>org.…...

买电脑注意事项之CPU型号后面的字母都代表什么意思
在 CPU 型号后面的字母通常表示该 CPU 的一些特性或用途。不同的字母可能代表不同的系列、性能级别、功耗特性等。以下是一些常见的 CPU 后缀字母及其可能的含义: U(例如:i5-8250U): Ultra Low Power:表示低功耗&#…...

Transformer实战-系列教程11:SwinTransformer 源码解读4(WindowAttention类)
🚩🚩🚩Transformer实战-系列教程总目录 有任何问题欢迎在下面留言 本篇文章的代码运行界面均在Pycharm中进行 本篇文章配套的代码资源已经上传 点我下载源码 SwinTransformer 算法原理 SwinTransformer 源码解读1(项目配置/SwinTr…...

Jenkins(本地Windows上搭建)上传 Pipeline构建前端项目并将生成dist文件夹上传至指定服务器
下载安装jdk https://www.oracle.com/cn/java/technologies/downloads/#jdk21-windows 下载jenkins window版 双击安装 https://www.jenkins.io/download/thank-you-downloading-windows-installer-stable/ 网页输入 http://localhost:8088/ 输入密码、设置账号、安装推…...

Elasticsearch 安装和配置脚本文档
Elasticsearch 安装和配置脚本文档 目录 **Elasticsearch 安装和配置脚本文档**0.**概述**1.**使用方法:**2.**脚本步骤:**3. **完整代码如下:** 0.概述 此Bash脚本用于自动化在CentOS 7系统上安装和配置Elasticsearch(ES&#x…...

【Android辟邪】之:gradle——在项目间共享依赖关系版本
翻译和简单修改自:https://docs.gradle.org/current/userguide/platforms.html#sec:sharing-catalogs 建议看原文(有能力的话) 现在 Gradle 脚本可以使用两种语法编写:Kotlin 和 Groovy 本文只使用kotlin脚本语法,更…...

Qt 项目树工程,拷贝子项目dll到子项目exe运行路径
1、项目树工程 2、项目树列表 ---- BuildAll -------- App (exe) -------- Database (dll) 注:使用 子项目–>添加库–>内部库 的方式 3、qmake 内置的变量 $$OUT_PWD 表示输出文件(如可执行文件…...

进程间通信方式
1>内核提供的原始通信方式有三种 1)无名管道 2)有名管道 3)信号 2>System V提供了三种通信方式 4)消息队列 5)共享内存 6)信号量(信号灯集) 3>套接字通信 7)socke…...

[linux]:匿名管道和命名管道(什么是管道,怎么创建管道(函数),匿名管道和命名管道的区别,代码例子)
目录 一、匿名管道 1.什么是管道?什么是匿名管道? 2.怎么创建匿名管道(函数) 3.匿名管道的4种情况 4.匿名管道有5种特性 5.怎么使用匿名管道?匿名管道有什么用?(例子) 二、命名…...

Python调用matlab程序
matlab官网:https://ww2.mathworks.cn/?s_tidgn_logo matlab外部语言和库接口,包括 Python、Java、C、C、.NET 和 Web 服务。 matlab和python的版本 安装依赖配置 安装matlab的engine 找到matlab的安装目录:“xxx\ extern\engines\python…...

FlinkSql 窗口函数
Windowing TVF 以前用的是Grouped Window Functions(分组窗口函数),但是分组窗口函数只支持窗口聚合 现在FlinkSql统一都是用的是Windowing TVFs(窗口表值函数),Windowing TVFs更符合 SQL 标准且更加强大…...

十分钟GIS——geoserver+postgis+udig从零开始发布地图服务
1数据库部署 1.1PostgreSql安装 下载到安装文件后(postgresql-9.2.19-1-windows-x64.exe),双击安装。 指定安装目录,如下图所示 指定数据库文件存放目录位置,如下图所示 指定数据库访问管理员密码,如下图所…...

鸿蒙(HarmonyOS)项目方舟框架(ArkUI)之Span组件
鸿蒙(HarmonyOS)项目方舟框架(ArkUI)之Span组件 一、操作环境 操作系统: Windows 10 专业版、IDE:DevEco Studio 3.1、SDK:HarmonyOS 3.1 二、Span组件 鸿蒙(HarmonyOS)作为Text组件的子组件࿰…...

Leetcode—42. 接雨水【困难】
2024每日刷题(112) Leetcode—42. 接雨水 空间复杂度为O(n)的算法思想 实现代码 class Solution { public:int trap(vector<int>& height) {int ans 0;int n height.size();vector<int> l(n);vector<int> r(n);for(int i 0; …...

[Python] opencv - 什么是直方图?如何绘制图像的直方图?如何对直方图进行均匀化处理?
什么是直方图? 直方图是一种统计图,用于展示数据的分布情况。它将数据按照一定的区间或者组进行划分,然后计算在每个区间或组内的数据频数或频率(即数据出现的次数或占比),然后用矩形或者柱形图的形式将这…...

ppi rust开发 python调用
创建python的一个测试工程 python -m venv venv .\venv\Scripts\activatepip install cffi创建一个rust的lib项目 cargo new --lib pyrustlib.rs #[no_mangle] pub extern "C" fn rust_add(x: i32, y: i32) -> i32 {x y }Cargo.toml [package] name "p…...

网站后端开发 thinkphp6 入门教程合集(更新中)
thinkphp6 入门(1)--安装、路由规则、多应用模式 thinkphp6 入门(1)--安装、路由规则、多应用模式_软件工程小施同学的博客-CSDN博客 thinkphp6 入门(2)--视图、渲染html页面、赋值 thinkphp6 入门&#x…...

Web前端框架-Vue(初识)
文章目录 web前端三大主流框架**1.Angular****2.React****3.Vue**什么是Vue.js 为什么要学习流行框架框架和库和插件的区别一.简介指令v-cloakv-textv-htmlv-pre**v-once**v-onv-on事件函数中传入参数事件修饰符双向数据绑定v-model 按键修饰符自定义按键修饰符别名v-bind(属性…...

配置dns服务的正反向解析
服务端IP客户端IP网址192.168.153.137192.168.153.www.openlab.com 1:正向解析 1.1关闭客户端和服务端的安全软件,安装bind软件 [rootserver ~]# setenforce 0 [rootserver ~]# systemctl stop firewalld [rootserver ~]# yum install bind -y [rootnod…...

小白水平理解面试经典题目LeetCode 71. Simplify Path【Stack类】
71. 简化路径 小白渣翻译 给定一个字符串 path ,它是 Unix 风格文件系统中文件或目录的绝对路径(以斜杠 ‘/’ 开头),将其转换为简化的规范路径。 在 Unix 风格的文件系统中,句点 ‘.’ 指的是当前目录,…...

电力负荷预测 | 电力系统负荷预测模型(Python线性回归、随机森林、支持向量机、BP神经网络、GRU、LSTM)
文章目录 效果一览文章概述源码设计参考资料效果一览 文章概述 电力系统负荷预测模型(Python线性回归、随机森林、支持向量机、BP神经网络、GRU、LSTM) 所谓预测,就是指通过对事物进行分析及研究,并运用合理的方法探索事物的发展变化规律,对其未来发展做出预先估计和判断。…...

YY调音台:音频后期处理
我从事影视后期处理的工作,主要负责音频、音效合成这块工作内容。在影视作品中,声音不仅仅是背景元素,它在叙事和创造情感氛围上发挥着至关重要的作用。我们的工作不仅要让听众听到声音,更要让他们通过声音感受到情感的波动和故事…...

一键部署一个监控系统hertzbeat
效果 特点 一站式监控告警通知,支持应用服务,数据库,操作系统,中间件,云原生,网络等。 易用友好,无需 Agent,全页面操作,鼠标点一点就能监控告警。 强大监控模版能力&…...

为电子表格嵌入数据库,Excel/WPS一键升级为管理系统
将Excel表格转化为管理系统,这款工具能够实现只需导入表格数据,即可自动生成相应的软件和APP。 表格办公的烦恼,有遇到吧? 对于具有一定规模的企业而言,各类表格如同繁星般众多,既有日常使用的常规表格&a…...

搜索与图论(一)(深搜,广搜,树与图的存储遍历,拓扑排序)
一、DFS 往深里搜,搜到叶子结点那里,回溯,到可以继续到叶子结点深搜的位置。 1、回溯一定要恢复现场 2、定义一个与当前递归层数有关的终止条件(题目要求的东西) 3、每层都用循环判断是否存在可以dfs的路 输出数字…...

【开源】基于JAVA+Vue+SpringBoot的停车场收费系统
目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块2.1 停车位模块2.2 车辆模块2.3 停车收费模块2.4 IC卡模块2.5 IC卡挂失模块 三、系统设计3.1 用例设计3.2 数据库设计3.2.1 停车场表3.2.2 车辆表3.2.3 停车收费表3.2.4 IC 卡表3.2.5 IC 卡挂失表 四、系统实现五、核心代码…...

DDoS攻击激增,分享高效可靠的DDoS防御方案
当下DDoS攻击规模不断突破上限,形成了 "网络威胁格局中令人不安的趋势"。专业数据显示,对比2022年上半年与2023年上半年,所有行业的DDoS攻击频率增加了314%。其中零售、电信和媒体公司遭受的攻击规模最大,三个垂直行业的…...

打卡今天学习的命令 (linux
1.1 cp - 复制文件或目录 cp source destination cp -r source_directory destination # 递归复制目录及其内容1.2 rm - 删除文件或目录 rm file rm -r directory # 递归删除目录及其内容1.3 mv - 移动/重命名文件或目录 mv source destination mv old_name new_name # 重…...

[C#]无法获取源 https://api.nuge t.org/v3-index存储签名信息解决方法
参考网上大部分方法错误,根本不起作用。正确方法是 C:\Users\你的用户名\AppData\Roaming\NuGet找到NuGet.Config打开,看到类似下面信息(可能不一样) <?xml version"1.0" encoding"utf-8"?> <co…...

FRP内网穿透如何避免SSH暴力破解(二)——指定地区允许访问
背景 上篇文章说到,出现了试图反复通过FRP的隧道,建立外网端口到内网服务器TCP链路的机器人,同时试图暴力破解ssh。这些连接造成了流量的浪费和不必要的通信开销。考虑到服务器使用者主要分布在A、B、C地区和国家,我打算对上一篇…...