记得上下班打卡 | git大法好,push需谨慎

Commit 6438e0d1 authored by anjiabin's avatar anjiabin

修改通知逻辑

parent 9fb463ab
package com.liquidnet.service.dragon.config;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.receiver.RedisPayNotifyReceiver;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.StreamOffset;
import org.springframework.data.redis.stream.StreamMessageListenerContainer;
import org.springframework.data.redis.stream.Subscription;
import java.time.Duration;
@Configuration
public class RedisStreamConfig {
@Autowired
private RedisPayNotifyReceiver redisPayNotifyReceiver;
@Bean
public Subscription subscriptionAlipayNotify0(RedisConnectionFactory factory) {
var options = StreamMessageListenerContainer
.StreamMessageListenerContainerOptions
.builder()
.pollTimeout(Duration.ofMillis(1))
.build();
var listenerContainer = StreamMessageListenerContainer.create(factory, options);
var subscription = listenerContainer.receiveAutoAck(Consumer.from(DragonConstant.ChannelRedisQueueEnum.ALIPAY_PAY_GROUP.getCode(), "alipay-pay-notify-0"),
StreamOffset.create(DragonConstant.ChannelRedisQueueEnum.ALIPAY_PAY_KEY.getCode(), ReadOffset.lastConsumed()), redisPayNotifyReceiver);
listenerContainer.start();
return subscription;
}
@Bean
public Subscription subscriptionAlipayNotify1(RedisConnectionFactory factory) {
var options = StreamMessageListenerContainer
.StreamMessageListenerContainerOptions
.builder()
.pollTimeout(Duration.ofMillis(1))
.build();
var listenerContainer = StreamMessageListenerContainer.create(factory, options);
var subscription = listenerContainer.receiveAutoAck(Consumer.from(DragonConstant.ChannelRedisQueueEnum.ALIPAY_PAY_GROUP.getCode(), "alipay-pay-notify-1"),
StreamOffset.create(DragonConstant.ChannelRedisQueueEnum.ALIPAY_PAY_KEY.getCode(), ReadOffset.lastConsumed()), redisPayNotifyReceiver);
listenerContainer.start();
return subscription;
}
@Bean
public Subscription subscriptionWepayNotify0(RedisConnectionFactory factory) {
var options = StreamMessageListenerContainer
.StreamMessageListenerContainerOptions
.builder()
.pollTimeout(Duration.ofMillis(1))
.build();
var listenerContainer = StreamMessageListenerContainer.create(factory, options);
var subscription = listenerContainer.receiveAutoAck(Consumer.from(DragonConstant.ChannelRedisQueueEnum.WECHAT_PAY_GROUP.getCode(), "wepay-pay-notify-0"),
StreamOffset.create(DragonConstant.ChannelRedisQueueEnum.WECHAT_PAY_KEY.getCode(), ReadOffset.lastConsumed()), redisPayNotifyReceiver);
listenerContainer.start();
return subscription;
}
// @Autowired
// private RedisPayNotifyReceiver redisPayNotifyReceiver;
@Bean
public Subscription subscriptionWepayNotify1(RedisConnectionFactory factory) {
var options = StreamMessageListenerContainer
.StreamMessageListenerContainerOptions
.builder()
.pollTimeout(Duration.ofMillis(1))
.build();
var listenerContainer = StreamMessageListenerContainer.create(factory, options);
var subscription = listenerContainer.receiveAutoAck(Consumer.from(DragonConstant.ChannelRedisQueueEnum.WECHAT_PAY_GROUP.getCode(), "wepay-pay-notify-1"),
StreamOffset.create(DragonConstant.ChannelRedisQueueEnum.WECHAT_PAY_KEY.getCode(), ReadOffset.lastConsumed()), redisPayNotifyReceiver);
listenerContainer.start();
return subscription;
}
// @Bean
// public Subscription subscriptionAlipayNotify0(RedisConnectionFactory factory) {
// var options = StreamMessageListenerContainer
// .StreamMessageListenerContainerOptions
// .builder()
// .pollTimeout(Duration.ofMillis(1))
// .build();
// var listenerContainer = StreamMessageListenerContainer.create(factory, options);
// var subscription = listenerContainer.receiveAutoAck(Consumer.from(DragonConstant.ChannelRedisQueueEnum.ALIPAY_PAY_GROUP.getCode(), "alipay-pay-notify-0"),
// StreamOffset.create(DragonConstant.ChannelRedisQueueEnum.ALIPAY_PAY_KEY.getCode(), ReadOffset.lastConsumed()), redisPayNotifyReceiver);
// listenerContainer.start();
// return subscription;
// }
//
// @Bean
// public Subscription subscriptionAlipayNotify1(RedisConnectionFactory factory) {
// var options = StreamMessageListenerContainer
// .StreamMessageListenerContainerOptions
// .builder()
// .pollTimeout(Duration.ofMillis(1))
// .build();
// var listenerContainer = StreamMessageListenerContainer.create(factory, options);
// var subscription = listenerContainer.receiveAutoAck(Consumer.from(DragonConstant.ChannelRedisQueueEnum.ALIPAY_PAY_GROUP.getCode(), "alipay-pay-notify-1"),
// StreamOffset.create(DragonConstant.ChannelRedisQueueEnum.ALIPAY_PAY_KEY.getCode(), ReadOffset.lastConsumed()), redisPayNotifyReceiver);
// listenerContainer.start();
// return subscription;
// }
//
// @Bean
// public Subscription subscriptionWepayNotify0(RedisConnectionFactory factory) {
// var options = StreamMessageListenerContainer
// .StreamMessageListenerContainerOptions
// .builder()
// .pollTimeout(Duration.ofMillis(1))
// .build();
// var listenerContainer = StreamMessageListenerContainer.create(factory, options);
// var subscription = listenerContainer.receiveAutoAck(Consumer.from(DragonConstant.ChannelRedisQueueEnum.WECHAT_PAY_GROUP.getCode(), "wepay-pay-notify-0"),
// StreamOffset.create(DragonConstant.ChannelRedisQueueEnum.WECHAT_PAY_KEY.getCode(), ReadOffset.lastConsumed()), redisPayNotifyReceiver);
// listenerContainer.start();
// return subscription;
// }
//
// @Bean
// public Subscription subscriptionWepayNotify1(RedisConnectionFactory factory) {
// var options = StreamMessageListenerContainer
// .StreamMessageListenerContainerOptions
// .builder()
// .pollTimeout(Duration.ofMillis(1))
// .build();
// var listenerContainer = StreamMessageListenerContainer.create(factory, options);
// var subscription = listenerContainer.receiveAutoAck(Consumer.from(DragonConstant.ChannelRedisQueueEnum.WECHAT_PAY_GROUP.getCode(), "wepay-pay-notify-1"),
// StreamOffset.create(DragonConstant.ChannelRedisQueueEnum.WECHAT_PAY_KEY.getCode(), ReadOffset.lastConsumed()), redisPayNotifyReceiver);
// listenerContainer.start();
// return subscription;
// }
}
package com.liquidnet.service.dragon.receiver;
import com.liquidnet.commons.lang.util.HttpUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.dragon.bo.PayNotifyReqBo;
import com.liquidnet.service.dragon.dto.PayNotifyDto;
import com.liquidnet.service.dragon.utils.MqHandleUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.stream.StreamListener;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.time.LocalDateTime;
/**
* 支付回调通知商户
*/
@Slf4j
@Component
public class RedisPayNotifyReceiver implements StreamListener<String, MapRecord<String, String, String>> {
@Autowired
private MqHandleUtil mqHandleUtil;
@Override
public void onMessage(MapRecord<String, String, String> message) {
log.info("接受到来自redis notify 的消息");
log.info("message id "+message.getId());
log.info("stream "+message.getStream());
log.info("body "+message.getValue());
this.sendNotify(message.getValue().get("message"));
}
private void sendNotify(String message){
PayNotifyReqBo payNotifyReqBo = JsonUtils.fromJson(message, PayNotifyReqBo.class);
PayNotifyDto payNotifyDto = payNotifyReqBo.getPayNotifyDto();
LocalDateTime nowTime = LocalDateTime.now();
MultiValueMap<String, String> params = new LinkedMultiValueMap();
params.add("status", payNotifyDto.getStatus().toString());
params.add("type", payNotifyDto.getType());
params.add("code", payNotifyDto.getCode());
params.add("paymentId", payNotifyDto.getPaymentId());
params.add("orderCode", payNotifyDto.getOrderCode());
params.add("price", payNotifyDto.getPrice().toString());
params.add("paymentType", payNotifyDto.getPaymentType());
String response = HttpUtil.post(payNotifyReqBo.getNotifyUrl(), params);
log.debug("PAY RESPONSE=" + response);
if (response.equals("success")) {
// MqHandleUtilsendMySqlRedis(
// SqlMapping.get("dragon_order_pay.update"),
// new Object[]{nowTime, DateUtil.Formatter.yyyyMMddHHmmss.format(nowTime), DragonConstant.RefundStatusEnum.STATUS_SUCCESS.getCode(), notifyUrlDto.getRefundCode()}
// );
} else {
// sendMySqlRedis(
// SqlMapping.get("dragon_order_pay.update"),
// new Object[]{nowTime, DateUtil.Formatter.yyyyMMddHHmmss.format(nowTime), DragonConstant.RefundStatusEnum.STATUS_FAIL.getCode(), notifyUrlDto.getRefundCode()}
// );
}
}
}
//package com.liquidnet.service.dragon.receiver;
//
//import com.liquidnet.commons.lang.util.HttpUtil;
//import com.liquidnet.commons.lang.util.JsonUtils;
//import com.liquidnet.service.dragon.bo.PayNotifyReqBo;
//import com.liquidnet.service.dragon.dto.PayNotifyDto;
//import com.liquidnet.service.dragon.utils.MqHandleUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.connection.stream.MapRecord;
//import org.springframework.data.redis.stream.StreamListener;
//import org.springframework.stereotype.Component;
//import org.springframework.util.LinkedMultiValueMap;
//import org.springframework.util.MultiValueMap;
//
//import java.time.LocalDateTime;
//
///**
// * 支付回调通知商户
// */
//@Slf4j
//@Component
//public class RedisPayNotifyReceiver implements StreamListener<String, MapRecord<String, String, String>> {
//
// @Autowired
// private MqHandleUtil mqHandleUtil;
// @Override
// public void onMessage(MapRecord<String, String, String> message) {
// log.info("接受到来自redis notify 的消息");
// log.info("message id "+message.getId());
// log.info("stream "+message.getStream());
// log.info("body "+message.getValue());
// this.sendNotify(message.getValue().get("message"));
// }
//
// private void sendNotify(String message){
// PayNotifyReqBo payNotifyReqBo = JsonUtils.fromJson(message, PayNotifyReqBo.class);
// PayNotifyDto payNotifyDto = payNotifyReqBo.getPayNotifyDto();
// LocalDateTime nowTime = LocalDateTime.now();
// MultiValueMap<String, String> params = new LinkedMultiValueMap();
// params.add("status", payNotifyDto.getStatus().toString());
// params.add("type", payNotifyDto.getType());
// params.add("code", payNotifyDto.getCode());
// params.add("paymentId", payNotifyDto.getPaymentId());
// params.add("orderCode", payNotifyDto.getOrderCode());
// params.add("price", payNotifyDto.getPrice().toString());
// params.add("paymentType", payNotifyDto.getPaymentType());
// String response = HttpUtil.post(payNotifyReqBo.getNotifyUrl(), params);
// log.debug("PAY RESPONSE=" + response);
// if (response.equals("success")) {
//// MqHandleUtilsendMySqlRedis(
//// SqlMapping.get("dragon_order_pay.update"),
//// new Object[]{nowTime, DateUtil.Formatter.yyyyMMddHHmmss.format(nowTime), DragonConstant.RefundStatusEnum.STATUS_SUCCESS.getCode(), notifyUrlDto.getRefundCode()}
//// );
// } else {
//// sendMySqlRedis(
//// SqlMapping.get("dragon_order_pay.update"),
//// new Object[]{nowTime, DateUtil.Formatter.yyyyMMddHHmmss.format(nowTime), DragonConstant.RefundStatusEnum.STATUS_FAIL.getCode(), notifyUrlDto.getRefundCode()}
//// );
// }
// }
//}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment