|
|
@ -1,5 +1,7 @@
|
|
|
|
package com.shun.integral.controller;
|
|
|
|
package com.shun.integral.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.amqp.core.Message;
|
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
|
@ -19,4 +21,31 @@ public class IntegralController {
|
|
|
|
Thread.sleep(400);
|
|
|
|
Thread.sleep(400);
|
|
|
|
System.out.println("扣除用户积分成功!!");
|
|
|
|
System.out.println("扣除用户积分成功!!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final String ID_NAME = "spring_returned_message_correlation";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @Transactional
|
|
|
|
|
|
|
|
// public void consume(Message message) {
|
|
|
|
|
|
|
|
// // 获取生产者提供的CorrelationId要基于header去获取。
|
|
|
|
|
|
|
|
// String id = message.getMessageProperties().getHeader(ID_NAME);
|
|
|
|
|
|
|
|
// //1、查询幂等表是否存在当前消息标识
|
|
|
|
|
|
|
|
// int count = userPointsIdempotentMapper.findById(id);
|
|
|
|
|
|
|
|
// //2、如果存在,直接return结束
|
|
|
|
|
|
|
|
// if(count == 1){
|
|
|
|
|
|
|
|
// log.info("消息已经被消费!!!无需重复消费!");
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// //3、如果不存在,插入消息标识到幂等表
|
|
|
|
|
|
|
|
// userPointsIdempotentMapper.save(id);
|
|
|
|
|
|
|
|
// //4、执行消费逻辑
|
|
|
|
|
|
|
|
// // 预扣除用户积分
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// Thread.sleep(400);
|
|
|
|
|
|
|
|
// } catch (InterruptedException e) {
|
|
|
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// System.out.println("扣除用户积分成功!!");
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|