mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-23 05:00:25 +08:00
feat:RabbitMQ整合Canal
This commit is contained in:
parent
7f53af0f90
commit
4be51030f0
@ -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;
|
||||
|
||||
/**
|
||||
* 订单超时未支付,关闭订单,释放库存
|
||||
|
@ -104,16 +104,16 @@
|
||||
<artifactId>common-elasticsearch</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.youlai</groupId>
|
||||
<artifactId>common-mybatis</artifactId>
|
||||
<version>${youlai.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.youlai</groupId>
|
||||
<artifactId>common-rabbitmq</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user