记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董敬伟
liquidnet-bus-v1
Commits
6438e0d1
Commit
6438e0d1
authored
Jul 16, 2021
by
anjiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改通知逻辑
parent
9fb463ab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
132 deletions
+119
-132
RedisStreamConfig.java
...om/liquidnet/service/dragon/config/RedisStreamConfig.java
+57
-70
RedisPayNotifyReceiver.java
...idnet/service/dragon/receiver/RedisPayNotifyReceiver.java
+62
-62
No files found.
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/config/RedisStreamConfig.java
View file @
6438e0d1
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;
// }
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/receiver/RedisPayNotifyReceiver.java
View file @
6438e0d1
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()}
// );
//
//
);
}
//
}
}
//
}
}
//
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment