From 4be51030f0348dd81fd0b03bb3e6d316e4196027 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9C=89=E6=9D=A5=E6=8A=80=E6=9C=AF?= <1490493387@qq.com>
Date: Thu, 4 Nov 2021 23:55:01 +0800
Subject: [PATCH] =?UTF-8?q?feat:RabbitMQ=E6=95=B4=E5=90=88Canal?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../mall/oms/listener/OrderListener.java | 10 +++---
youlai-admin/admin-boot/pom.xml | 8 ++---
.../youlai/admin/listener/CanalListener.java | 35 +++++++++++++++++++
.../mobile/SmsCodeAuthenticationProvider.java | 8 ++---
.../extension/wechat/WechatTokenGranter.java | 1 +
.../rabbitmq/config/RabbitMqConfig.java | 20 -----------
6 files changed, 49 insertions(+), 33 deletions(-)
create mode 100644 youlai-admin/admin-boot/src/main/java/com/youlai/admin/listener/CanalListener.java
diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/listener/OrderListener.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/listener/OrderListener.java
index 3396a55a1..96b95dc2a 100644
--- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/listener/OrderListener.java
+++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/listener/OrderListener.java
@@ -5,11 +5,13 @@ import com.youlai.mall.oms.service.IOrderItemService;
import com.youlai.mall.oms.service.IOrderService;
import com.youlai.mall.pms.api.StockFeignClient;
import lombok.AllArgsConstructor;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
+
import java.io.IOException;
/**
@@ -18,14 +20,12 @@ import java.io.IOException;
*/
@Component
-@AllArgsConstructor
@Slf4j
+@RequiredArgsConstructor
public class OrderListener {
- IOrderService orderService;
- IOrderItemService orderItemService;
- StockFeignClient stockFeignClient;
- RabbitTemplate rabbitTemplate;
+ private final IOrderService orderService;
+ private final StockFeignClient stockFeignClient;
/**
* 订单超时未支付,关闭订单,释放库存
diff --git a/youlai-admin/admin-boot/pom.xml b/youlai-admin/admin-boot/pom.xml
index 00aa733b1..a75c9ade8 100644
--- a/youlai-admin/admin-boot/pom.xml
+++ b/youlai-admin/admin-boot/pom.xml
@@ -104,16 +104,16 @@
common-elasticsearch
-
com.youlai
common-mybatis
${youlai.version}
-
-
-
+
+ com.youlai
+ common-rabbitmq
+
diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/listener/CanalListener.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/listener/CanalListener.java
new file mode 100644
index 000000000..33faea8cd
--- /dev/null
+++ b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/listener/CanalListener.java
@@ -0,0 +1,35 @@
+package com.youlai.admin.listener;
+
+import com.rabbitmq.client.Channel;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.ExchangeTypes;
+import org.springframework.amqp.core.Message;
+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.messaging.handler.annotation.Payload;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+
+/**
+ * @author haoxr
+ * @date 2021/11/4 23:14
+ */
+@Component
+@Slf4j
+public class CanalListener {
+
+ @RabbitListener(bindings = {
+ @QueueBinding(
+ value = @Queue(value = "canal.queue", durable = "true"),
+ exchange = @Exchange(value = "canal.exchange"),
+ key = "canal.routing.key"
+ )
+ })
+ public void handleDataChange(String message) {
+ log.info("test接收到消息。message:{}", message);
+ }
+
+}
diff --git a/youlai-auth/src/main/java/com/youlai/auth/security/extension/mobile/SmsCodeAuthenticationProvider.java b/youlai-auth/src/main/java/com/youlai/auth/security/extension/mobile/SmsCodeAuthenticationProvider.java
index 7288a9c82..9157c3f4a 100644
--- a/youlai-auth/src/main/java/com/youlai/auth/security/extension/mobile/SmsCodeAuthenticationProvider.java
+++ b/youlai-auth/src/main/java/com/youlai/auth/security/extension/mobile/SmsCodeAuthenticationProvider.java
@@ -35,18 +35,18 @@ public class SmsCodeAuthenticationProvider implements AuthenticationProvider {
String mobile = (String) authenticationToken.getPrincipal();
String code = (String) authenticationToken.getCredentials();
- if (!code.equals("666666")) { // 666666 是后门,因为短信收费,实际环境删除这个if分支
+ if (!code.equals("666666")) { // 666666 是后门,因为短信收费,正式环境删除这个if分支
String codeKey = SecurityConstants.SMS_CODE_PREFIX + mobile;
String correctCode = redisTemplate.opsForValue().get(codeKey);
// 验证码比对
if (StrUtil.isBlank(correctCode) || !code.equals(correctCode)) {
throw new BizException("验证码不正确");
- } else {
- redisTemplate.delete(codeKey);
}
+ // 比对成功删除缓存的验证码
+ redisTemplate.delete(codeKey);
}
UserDetails userDetails = ((MemberUserDetailsServiceImpl) userDetailsService).loadUserByMobile(mobile);
- WechatAuthenticationToken result = new WechatAuthenticationToken(userDetails, new HashSet<>());
+ SmsCodeAuthenticationToken result = new SmsCodeAuthenticationToken(userDetails, new HashSet<>());
result.setDetails(authentication.getDetails());
return result;
}
diff --git a/youlai-auth/src/main/java/com/youlai/auth/security/extension/wechat/WechatTokenGranter.java b/youlai-auth/src/main/java/com/youlai/auth/security/extension/wechat/WechatTokenGranter.java
index cdd6a0dd1..bf5d6015c 100644
--- a/youlai-auth/src/main/java/com/youlai/auth/security/extension/wechat/WechatTokenGranter.java
+++ b/youlai-auth/src/main/java/com/youlai/auth/security/extension/wechat/WechatTokenGranter.java
@@ -42,6 +42,7 @@ public class WechatTokenGranter extends AbstractTokenGranter {
String encryptedData = parameters.get("encryptedData");
String iv = parameters.get("iv");
+ // 过河拆桥,移除后续无用参数
parameters.remove("code");
parameters.remove("encryptedData");
parameters.remove("iv");
diff --git a/youlai-common/common-rabbitmq/src/main/java/com/youlai/common/rabbitmq/config/RabbitMqConfig.java b/youlai-common/common-rabbitmq/src/main/java/com/youlai/common/rabbitmq/config/RabbitMqConfig.java
index 0d705320b..02baa0a9a 100644
--- a/youlai-common/common-rabbitmq/src/main/java/com/youlai/common/rabbitmq/config/RabbitMqConfig.java
+++ b/youlai-common/common-rabbitmq/src/main/java/com/youlai/common/rabbitmq/config/RabbitMqConfig.java
@@ -1,9 +1,5 @@
package com.youlai.common.rabbitmq.config;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
-import org.springframework.amqp.support.converter.MessageConverter;
-import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@@ -15,23 +11,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
*/
@Configuration
@EnableTransactionManagement
-@Slf4j
public class RabbitMqConfig {
-// @Autowired
-// private RabbitTemplate rabbitTemplate;
-
- /**
- * 使用json序列化机制,进行消息转换
- *
- * @return
- */
- @Bean
- public MessageConverter jackson2MessageConverter() {
- return new Jackson2JsonMessageConverter();
- }
-
-
-
}