feat:RabbitMQ整合Canal

This commit is contained in:
有来技术 2021-11-04 23:55:01 +08:00
parent 7f53af0f90
commit 4be51030f0
6 changed files with 49 additions and 33 deletions

View File

@ -5,11 +5,13 @@ import com.youlai.mall.oms.service.IOrderItemService;
import com.youlai.mall.oms.service.IOrderService; import com.youlai.mall.oms.service.IOrderService;
import com.youlai.mall.pms.api.StockFeignClient; import com.youlai.mall.pms.api.StockFeignClient;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message; import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
/** /**
@ -18,14 +20,12 @@ import java.io.IOException;
*/ */
@Component @Component
@AllArgsConstructor
@Slf4j @Slf4j
@RequiredArgsConstructor
public class OrderListener { public class OrderListener {
IOrderService orderService; private final IOrderService orderService;
IOrderItemService orderItemService; private final StockFeignClient stockFeignClient;
StockFeignClient stockFeignClient;
RabbitTemplate rabbitTemplate;
/** /**
* 订单超时未支付关闭订单释放库存 * 订单超时未支付关闭订单释放库存

View File

@ -104,16 +104,16 @@
<artifactId>common-elasticsearch</artifactId> <artifactId>common-elasticsearch</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.youlai</groupId> <groupId>com.youlai</groupId>
<artifactId>common-mybatis</artifactId> <artifactId>common-mybatis</artifactId>
<version>${youlai.version}</version> <version>${youlai.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.youlai</groupId>
<artifactId>common-rabbitmq</artifactId>
</dependency>
</dependencies> </dependencies>

View File

@ -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 <a href="mailto:xianrui0365@163.com">haoxr</a>
* @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);
}
}

View File

@ -35,18 +35,18 @@ public class SmsCodeAuthenticationProvider implements AuthenticationProvider {
String mobile = (String) authenticationToken.getPrincipal(); String mobile = (String) authenticationToken.getPrincipal();
String code = (String) authenticationToken.getCredentials(); 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 codeKey = SecurityConstants.SMS_CODE_PREFIX + mobile;
String correctCode = redisTemplate.opsForValue().get(codeKey); String correctCode = redisTemplate.opsForValue().get(codeKey);
// 验证码比对 // 验证码比对
if (StrUtil.isBlank(correctCode) || !code.equals(correctCode)) { if (StrUtil.isBlank(correctCode) || !code.equals(correctCode)) {
throw new BizException("验证码不正确"); throw new BizException("验证码不正确");
} else {
redisTemplate.delete(codeKey);
} }
// 比对成功删除缓存的验证码
redisTemplate.delete(codeKey);
} }
UserDetails userDetails = ((MemberUserDetailsServiceImpl) userDetailsService).loadUserByMobile(mobile); UserDetails userDetails = ((MemberUserDetailsServiceImpl) userDetailsService).loadUserByMobile(mobile);
WechatAuthenticationToken result = new WechatAuthenticationToken(userDetails, new HashSet<>()); SmsCodeAuthenticationToken result = new SmsCodeAuthenticationToken(userDetails, new HashSet<>());
result.setDetails(authentication.getDetails()); result.setDetails(authentication.getDetails());
return result; return result;
} }

View File

@ -42,6 +42,7 @@ public class WechatTokenGranter extends AbstractTokenGranter {
String encryptedData = parameters.get("encryptedData"); String encryptedData = parameters.get("encryptedData");
String iv = parameters.get("iv"); String iv = parameters.get("iv");
// 过河拆桥移除后续无用参数
parameters.remove("code"); parameters.remove("code");
parameters.remove("encryptedData"); parameters.remove("encryptedData");
parameters.remove("iv"); parameters.remove("iv");

View File

@ -1,9 +1,5 @@
package com.youlai.common.rabbitmq.config; 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.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
@ -15,23 +11,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
*/ */
@Configuration @Configuration
@EnableTransactionManagement @EnableTransactionManagement
@Slf4j
public class RabbitMqConfig { public class RabbitMqConfig {
// @Autowired
// private RabbitTemplate rabbitTemplate;
/**
* 使用json序列化机制进行消息转换
*
* @return
*/
@Bean
public MessageConverter jackson2MessageConverter() {
return new Jackson2JsonMessageConverter();
}
} }