init
This commit is contained in:
@@ -29,8 +29,8 @@ public class AmqpProducer {
|
||||
CommonDelayDto dto = new CommonDelayDto();
|
||||
dto.setType(type);
|
||||
dto.setRoomId(roomId);
|
||||
rabbitTemplate.convertAndSend(CheckTimeOutMqConfig.EXCHANGE_NAME,
|
||||
CheckTimeOutMqConfig.ROUTING_KEY,
|
||||
rabbitTemplate.convertAndSend(CommonDelayMqConfig.EXCHANGE_NAME,
|
||||
CommonDelayMqConfig.ROUTING_KEY,
|
||||
JSON.toJSONString(dto),
|
||||
messagePostProcessor -> {
|
||||
messagePostProcessor.getMessageProperties().setDelay(timeout*1000); // 设置延迟时间,单位毫秒
|
||||
|
||||
@@ -34,7 +34,7 @@ public class CheckTimeOutMqConfig {
|
||||
|
||||
@Bean
|
||||
public Binding delayedBinding(Queue delayedQueue,CustomExchange delayedExchange) {
|
||||
return BindingBuilder.bind(delayedQueue()).to(delayedExchange()).with(ROUTING_KEY).noargs();
|
||||
return BindingBuilder.bind(delayedQueue).to(delayedExchange).with(ROUTING_KEY).noargs();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class CommonDelayMqConfig {
|
||||
public static final String ROUTING_KEY = "commonDelayRouting";
|
||||
|
||||
@Bean
|
||||
public CustomExchange delayedExchange() {
|
||||
public CustomExchange commonDelayedExchange() {
|
||||
HashMap<String,Object> args = new HashMap<>();
|
||||
args.put("x-delayed-type", "direct");
|
||||
return new CustomExchange(EXCHANGE_NAME,
|
||||
@@ -26,15 +26,15 @@ public class CommonDelayMqConfig {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue delayedQueue() {
|
||||
public Queue commonDelayedQueue() {
|
||||
return QueueBuilder.durable(QUEUE_NAME)
|
||||
.withArgument("x-delayed-type", "direct")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding delayedBinding(Queue delayedQueue,CustomExchange delayedExchange) {
|
||||
return BindingBuilder.bind(delayedQueue()).to(delayedExchange()).with(ROUTING_KEY).noargs();
|
||||
public Binding commonDelayedBinding(Queue commonDelayedQueue,CustomExchange commonDelayedExchange) {
|
||||
return BindingBuilder.bind(commonDelayedQueue()).to(commonDelayedExchange()).with(ROUTING_KEY).noargs();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,11 +20,16 @@ public class CheckTimeOutMqConsumer {
|
||||
@RabbitListener(queues = CheckTimeOutMqConfig.QUEUE_NAME
|
||||
,containerFactory = "customContainerFactory")
|
||||
public void checkTimeOutMq(String message) {
|
||||
log.info("checkTimeOutMq: " + message);
|
||||
boolean next = settleService.withholdingFee(Long.valueOf(message));
|
||||
if(next){
|
||||
// 1分钟后继续执行
|
||||
amqpProducer.sendCheckTimeOut(message,60);
|
||||
log.info("开始执行预扣费: " + message);
|
||||
try {
|
||||
boolean next = settleService.withholdingFee(Long.valueOf(message));
|
||||
if(next){
|
||||
// 1分钟后继续执行
|
||||
amqpProducer.sendCheckTimeOut(message,60);
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("每分钟定时扣费失败!",e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user