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

Commit 6438e0d1 authored by anjiabin's avatar anjiabin

修改通知逻辑

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