7.19 配置RabbitMq
This commit is contained in:
parent
a8c43910d4
commit
3c54ed79d4
@ -13,6 +13,16 @@
|
|||||||
|
|
||||||
Date: 16/07/2025 17:08:44
|
Date: 16/07/2025 17:08:44
|
||||||
*/
|
*/
|
||||||
|
-- 如果存在就删除
|
||||||
|
DROP DATABASE IF EXISTS `pay-mall`;
|
||||||
|
|
||||||
|
-- 创建(如需指定字符集与排序规则,可自行调整)
|
||||||
|
CREATE DATABASE IF NOT EXISTS `group_buying_sys`
|
||||||
|
DEFAULT CHARACTER SET utf8mb4
|
||||||
|
COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- 切换到该库
|
||||||
|
USE `pay-mall`;
|
||||||
|
|
||||||
SET NAMES utf8mb4;
|
SET NAMES utf8mb4;
|
||||||
SET FOREIGN_KEY_CHECKS = 0;
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
@ -14,7 +14,7 @@ body{
|
|||||||
|
|
||||||
/* ========== 轮播图 ========== */
|
/* ========== 轮播图 ========== */
|
||||||
.swiper-container{
|
.swiper-container{
|
||||||
width:100%;height:375px;position:relative;overflow:hidden;
|
width:100%;height:375px;position:relative;overflow:hidden;margin-top: 10px;
|
||||||
}
|
}
|
||||||
.swiper-wrapper{display:flex;transition:transform .3s;}
|
.swiper-wrapper{display:flex;transition:transform .3s;}
|
||||||
.swiper-slide{flex:0 0 100%;height:375px;}
|
.swiper-slide{flex:0 0 100%;height:375px;}
|
||||||
@ -62,7 +62,14 @@ body{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ========== 拼单列表 ========== */
|
/* ========== 拼单列表 ========== */
|
||||||
.group-buying{background:#fff;padding:15px;margin-bottom:10px;position:relative;overflow:hidden;}
|
.group-buying {
|
||||||
|
background: #fff;
|
||||||
|
padding: 15px;
|
||||||
|
margin-bottom: 10px; /* 如果还想保留一点外边距 */
|
||||||
|
min-height: 230px; /* 根据需要调整数值 */
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
.section-title{
|
.section-title{
|
||||||
font-size:16px;font-weight:bold;margin-bottom:12px;position:relative;padding-left:10px;
|
font-size:16px;font-weight:bold;margin-bottom:12px;position:relative;padding-left:10px;
|
||||||
}
|
}
|
||||||
@ -71,7 +78,7 @@ body{
|
|||||||
width:3px;height:16px;background:#ff5000;border-radius:2px;
|
width:3px;height:16px;background:#ff5000;border-radius:2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.group-users{height:120px;position:relative;overflow:hidden;}
|
.group-users{height:180px;position:relative;overflow:hidden;}
|
||||||
.user-list{position:absolute;top:0;left:0;width:100%;transition:transform .5s ease;}
|
.user-list{position:absolute;top:0;left:0;width:100%;transition:transform .5s ease;}
|
||||||
|
|
||||||
.user-item{
|
.user-item{
|
||||||
|
@ -25,7 +25,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
/* =====================================================
|
/* =====================================================
|
||||||
* 1. 取接口数据并渲染
|
* 1. 取接口数据并渲染
|
||||||
* =================================================== */
|
* =================================================== */
|
||||||
const CFG_API = 'http://127.0.0.1:8091/api/v1/gbm/index/query_group_buy_market_config';
|
const CFG_API = '/api/v1/gbm/index/query_group_buy_market_config';
|
||||||
|
|
||||||
// 登录检查
|
// 登录检查
|
||||||
const loginToken = getCookie('loginToken');
|
const loginToken = getCookie('loginToken');
|
||||||
@ -86,7 +86,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
userList.innerHTML = '';
|
userList.innerHTML = '';
|
||||||
list.forEach(t => userList.appendChild(makeItem(t, groupPrice)));
|
list.forEach(t => userList.appendChild(makeItem(t, groupPrice)));
|
||||||
initUserMarquee();
|
initUserMarquee(3); // 显示 3 条
|
||||||
initCountdown();
|
initCountdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,28 +137,61 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
/* =====================================================
|
/* =====================================================
|
||||||
* 2. 拼单列表纵向轮播
|
* 2. 拼单列表纵向轮播
|
||||||
* =================================================== */
|
* =================================================== */
|
||||||
function initUserMarquee() {
|
function initUserMarquee(visibleCount = 3, interval = 3000, duration = 500) {
|
||||||
const items = userList.querySelectorAll('.user-item');
|
const box = document.querySelector('.group-users');
|
||||||
if (items.length <= 1) return;
|
const listEl = userList;
|
||||||
|
let originals = Array.from(listEl.children);
|
||||||
|
const total = originals.length;
|
||||||
|
|
||||||
const itemH = items[0].offsetHeight;
|
if (total === 0) return;
|
||||||
userList.appendChild(items[0].cloneNode(true));
|
// 如果原本就 <= 可见数,直接定高,不滚
|
||||||
|
if (total <= visibleCount) {
|
||||||
|
const h0 = originals[0].offsetHeight;
|
||||||
|
box.style.height = (h0 * visibleCount) + 'px';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let idx = 0;
|
// 1. 复制整份加入末尾
|
||||||
userList.addEventListener('transitionend', () => {
|
originals.forEach(item => listEl.appendChild(item.cloneNode(true)));
|
||||||
if (idx >= items.length) {
|
|
||||||
userList.style.transition = 'none';
|
// 2. 重新测量单条高度(此时 DOM 完整)
|
||||||
userList.style.transform = 'translateY(0)';
|
const itemH = listEl.children[0].offsetHeight;
|
||||||
idx = 0;
|
|
||||||
void userList.offsetWidth;
|
// 3. 设定窗口高度
|
||||||
|
box.style.height = (itemH * visibleCount) + 'px';
|
||||||
|
|
||||||
|
// 4. 状态
|
||||||
|
let index = 0;
|
||||||
|
let ticking = false;
|
||||||
|
|
||||||
|
function step() {
|
||||||
|
index++;
|
||||||
|
listEl.style.transition = `transform ${duration}ms ease`;
|
||||||
|
listEl.style.transform = `translateY(-${index * itemH}px)`;
|
||||||
|
}
|
||||||
|
|
||||||
|
listEl.addEventListener('transitionend', () => {
|
||||||
|
ticking = false;
|
||||||
|
// 5. 到达复制段的“第一帧”(index === total)就无缝重置
|
||||||
|
if (index === total) {
|
||||||
|
listEl.style.transition = 'none';
|
||||||
|
listEl.style.transform = 'translateY(0)';
|
||||||
|
index = 0;
|
||||||
|
// 强制 reflow 再恢复 transition
|
||||||
|
void listEl.offsetHeight;
|
||||||
|
listEl.style.transition = `transform ${duration}ms ease`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setInterval(() => {
|
const timer = setInterval(() => {
|
||||||
idx++;
|
if (!ticking) {
|
||||||
userList.style.transition = 'transform .5s ease';
|
ticking = true;
|
||||||
userList.style.transform = `translateY(${-idx * itemH}px)`;
|
step();
|
||||||
}, 3000);
|
}
|
||||||
|
}, interval);
|
||||||
|
|
||||||
|
// 可选:鼠标悬停暂停
|
||||||
|
listEl.addEventListener('mouseenter', () => clearInterval(timer));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =====================================================
|
/* =====================================================
|
||||||
@ -202,8 +235,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
/* =====================================================
|
/* =====================================================
|
||||||
* 4. 支付相关
|
* 4. 支付相关
|
||||||
* =================================================== */
|
* =================================================== */
|
||||||
const PAY_MALL_URL = 'http://127.0.0.1:8092';
|
const CREATE_PAY_API = `/api/v1/alipay/create_pay_order`;
|
||||||
const CREATE_PAY_API = `${PAY_MALL_URL}/api/v1/alipay/create_pay_order`;
|
|
||||||
|
|
||||||
// 4.1 支付确认弹窗
|
// 4.1 支付确认弹窗
|
||||||
function showPaymentConfirm(price){
|
function showPaymentConfirm(price){
|
||||||
|
@ -78,7 +78,10 @@
|
|||||||
<artifactId>converter-gson</artifactId>
|
<artifactId>converter-gson</artifactId>
|
||||||
<version>2.9.0</version>
|
<version>2.9.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
|
</dependency>
|
||||||
<!-- 工程模块;启动依赖 trigger->domain, infrastructure-->
|
<!-- 工程模块;启动依赖 trigger->domain, infrastructure-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>edu.whut</groupId>
|
<groupId>edu.whut</groupId>
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package edu.whut.config;
|
||||||
|
|
||||||
|
import org.springframework.amqp.core.Binding;
|
||||||
|
import org.springframework.amqp.core.BindingBuilder;
|
||||||
|
import org.springframework.amqp.core.Queue;
|
||||||
|
import org.springframework.amqp.core.TopicExchange;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RabbitMQConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消费拼团消息
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public Binding topicTeamSuccessBinding(
|
||||||
|
@Value("${spring.rabbitmq.config.consumer.topic_team_success.exchange}") String exchangeName,
|
||||||
|
@Value("${spring.rabbitmq.config.consumer.topic_team_success.routing_key}") String routingKey,
|
||||||
|
@Value("${spring.rabbitmq.config.consumer.topic_team_success.queue}") String queue) {
|
||||||
|
|
||||||
|
// 消息生产方的交换机
|
||||||
|
TopicExchange topicExchange = new TopicExchange(exchangeName, true, false);
|
||||||
|
|
||||||
|
return BindingBuilder.bind(new Queue(queue, true))
|
||||||
|
.to(topicExchange)
|
||||||
|
.with(routingKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -43,6 +43,28 @@ spring:
|
|||||||
connection-timeout: 30000 #数据库连接超时时间,默认30秒,即30000
|
connection-timeout: 30000 #数据库连接超时时间,默认30秒,即30000
|
||||||
connection-test-query: SELECT 1
|
connection-test-query: SELECT 1
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
type: com.zaxxer.hikari.HikariDataSource
|
||||||
|
# RabbitMQ
|
||||||
|
rabbitmq:
|
||||||
|
addresses: 192.168.10.218
|
||||||
|
port: 5672
|
||||||
|
username: admin
|
||||||
|
password: admin
|
||||||
|
listener:
|
||||||
|
simple:
|
||||||
|
prefetch: 1 # 每次投递n个消息,消费完在投递n个
|
||||||
|
template:
|
||||||
|
delivery-mode: persistent # 确保全局默认设置为持久化(可选)
|
||||||
|
# 消息配置
|
||||||
|
config:
|
||||||
|
consumer:
|
||||||
|
# 消费 topic 主题,team_success
|
||||||
|
topic_team_success:
|
||||||
|
# 绑定交换机 - 消息提供者的交换机
|
||||||
|
exchange: group_buy_market_exchange
|
||||||
|
# 消息主题
|
||||||
|
routing_key: topic.team_success
|
||||||
|
# 消费队列 - 每个系统有自己的消费队列
|
||||||
|
queue: pay_mall_queue_2_topic_team_success
|
||||||
|
|
||||||
# MyBatis 配置【如需使用记得打开】
|
# MyBatis 配置【如需使用记得打开】
|
||||||
mybatis:
|
mybatis:
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
spring:
|
spring:
|
||||||
profiles:
|
profiles:
|
||||||
active: prod,local
|
active: dev,local
|
||||||
|
@ -26,7 +26,10 @@
|
|||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
|
</dependency>
|
||||||
<!-- 系统模块 -->
|
<!-- 系统模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>edu.whut</groupId>
|
<groupId>edu.whut</groupId>
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package edu.whut.trigger.listener;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.amqp.core.ExchangeTypes;
|
||||||
|
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.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结算完成消息监听
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class TeamSuccessTopicListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定消费队列
|
||||||
|
*/
|
||||||
|
@RabbitListener(
|
||||||
|
bindings = @QueueBinding(
|
||||||
|
value = @Queue(value = "${spring.rabbitmq.config.consumer.topic_team_success.queue}"),
|
||||||
|
exchange = @Exchange(value = "${spring.rabbitmq.config.consumer.topic_team_success.exchange}", type = ExchangeTypes.TOPIC),
|
||||||
|
key = "${spring.rabbitmq.config.consumer.topic_team_success.routing_key}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
public void listener(String message) {
|
||||||
|
log.info("接收消息:{}", message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
6
pom.xml
6
pom.xml
@ -141,6 +141,12 @@
|
|||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
<version>5.8.26</version>
|
<version>5.8.26</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- rabbitmq https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-amqp -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
</dependency>
|
||||||
<!-- 工程模块 -->
|
<!-- 工程模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>edu.whut</groupId>
|
<groupId>edu.whut</groupId>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user