Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
O
operate-customer-service
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
沈振路
operate-customer-service
Commits
c45213f7
提交
c45213f7
authored
10月 24, 2022
作者:
沈振路
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
频率控制
上级
b0da370a
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
112 行增加
和
13 行删除
+112
-13
CustomerServiceCommonAsyncComponent.java
...tomer/components/CustomerServiceCommonAsyncComponent.java
+50
-0
RabbitConfig.java
...main/java/com/yaoyaozw/customer/configs/RabbitConfig.java
+17
-8
RabbitCommonNameConstant.java
...yaoyaozw/customer/constants/RabbitCommonNameConstant.java
+38
-0
TestController.java
...java/com/yaoyaozw/customer/controller/TestController.java
+7
-5
没有找到文件。
src/main/java/com/yaoyaozw/customer/components/CustomerServiceCommonAsyncComponent.java
浏览文件 @
c45213f7
...
...
@@ -8,9 +8,11 @@ import cn.hutool.json.JSONUtil;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.TypeReference
;
import
com.sun.org.apache.xpath.internal.operations.Bool
;
import
com.yaoyaozw.customer.common.R
;
import
com.yaoyaozw.customer.constants.ApiResultConstant
;
import
com.yaoyaozw.customer.constants.CustomerCommonConstant
;
import
com.yaoyaozw.customer.constants.RabbitCommonNameConstant
;
import
com.yaoyaozw.customer.entity.*
;
import
com.yaoyaozw.customer.enums.CustomerStoreTemplateEnum
;
import
com.yaoyaozw.customer.feigns.ReferralFeignClient
;
...
...
@@ -28,6 +30,8 @@ import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.scheduling.annotation.Async
;
...
...
@@ -69,6 +73,8 @@ public class CustomerServiceCommonAsyncComponent {
private
KanbanCommonMapper
kanbanCommonMapper
;
@Autowired
private
CustomerGraphicsDelayMapper
customerGraphicsDelayMapper
;
@Autowired
private
RabbitTemplate
rabbitTemplate
;
@Async
(
"myExecutor"
)
...
...
@@ -542,6 +548,7 @@ public class CustomerServiceCommonAsyncComponent {
* 以下是公有方法
*/
public
void
getCopyReferral
(
String
dateStr
,
AuthInfoVO
authInfoVo
,
ReferralEntity
referralEntity
)
{
ygAccessLimit
(
true
,
authInfoVo
.
getStoreType
());
referralEntity
.
setStoreType
(
authInfoVo
.
getStoreType
());
// 非常用链接类型的name需要处理
String
name
=
referralEntity
.
getName
();
...
...
@@ -600,7 +607,50 @@ public class CustomerServiceCommonAsyncComponent {
return
userEntityList
;
}
private
void
ygAccessLimit
(
Boolean
checkStoreType
,
String
storeType
)
{
if
(
checkStoreType
&&
!
CustomerCommonConstant
.
STORE_NAME_YANG_GUANG
.
equals
(
storeType
))
{
// 需要校验书城但是不是阳光书城,直接返回
return
;
}
boolean
go
;
synchronized
(
rabbitTemplate
)
{
// 从redis查询计数
Object
count
=
redisTemplate
.
opsForValue
().
get
(
CustomerCommonConstant
.
YANG_GUANG_ACCESS_LIMIT_REDIS_KEY
);
if
(
ObjectUtil
.
isNull
(
count
))
{
// redis中没有,设置0
redisTemplate
.
opsForValue
().
set
(
CustomerCommonConstant
.
YANG_GUANG_ACCESS_LIMIT_REDIS_KEY
,
0
);
count
=
0
;
}
LOCAL_LOG
.
info
(
"当前count: {}"
,
count
);
long
stamp
=
System
.
currentTimeMillis
();
// 判断计数是否达到上限
go
=
(
Integer
)
count
<
80
;
if
(
go
)
{
// 没有达到上限,发送消息并且计数加1
rabbitTemplate
.
convertAndSend
(
RabbitCommonNameConstant
.
OPERATE_COMMON_EXCHANGE
,
RabbitCommonNameConstant
.
YG_LIMIT_TTL_ROUTE_KEY
,
stamp
);
redisTemplate
.
opsForValue
().
increment
(
CustomerCommonConstant
.
YANG_GUANG_ACCESS_LIMIT_REDIS_KEY
);
}
}
if
(!
go
)
{
// 计数达到上限了,休眠30秒,递归调用
try
{
LOCAL_LOG
.
info
(
"达到上限, 休眠15秒"
);
Thread
.
sleep
(
15000
);
// 再次调用不需要校验书城
ygAccessLimit
(
false
,
""
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
@RabbitListener
(
queues
=
RabbitCommonNameConstant
.
YG_LIMIT_DEATH_QUEUE
)
public
void
listener
()
{
redisTemplate
.
opsForValue
().
decrement
(
CustomerCommonConstant
.
YANG_GUANG_ACCESS_LIMIT_REDIS_KEY
);
}
}
src/main/java/com/yaoyaozw/customer/configs/RabbitConfig.java
浏览文件 @
c45213f7
package
com
.
yaoyaozw
.
customer
.
configs
;
import
com.yaoyaozw.customer.constants.RabbitCommonNameConstant
;
import
org.springframework.amqp.core.Binding
;
import
org.springframework.amqp.core.BindingBuilder
;
import
org.springframework.amqp.core.DirectExchange
;
import
org.springframework.amqp.core.Queue
;
import
org.springframework.amqp.support.converter.Jackson2JsonMessageConverter
;
import
org.springframework.amqp.support.converter.MessageConverter
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -17,38 +20,44 @@ import java.util.Map;
@Configuration
public
class
RabbitConfig
{
/* @Bean
public MessageConverter messageConverter(){
return new Jackson2JsonMessageConverter();
}*/
@Bean
public
Queue
directQueue
(){
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
4
);
map
.
put
(
"x-dead-letter-exchange"
,
"DEATH_EXCHANGE"
);
map
.
put
(
"x-dead-letter-routing-key"
,
"death"
);
map
.
put
(
"x-dead-letter-exchange"
,
RabbitCommonNameConstant
.
DEATH_EXCHANGE
);
map
.
put
(
"x-dead-letter-routing-key"
,
RabbitCommonNameConstant
.
YG_LIMIT_DEATH_ROUTE_KEY
);
map
.
put
(
"x-message-ttl"
,
60000
);
return
new
Queue
(
"YG_ACCESS_LIMIT"
,
true
,
false
,
false
,
map
);
return
new
Queue
(
RabbitCommonNameConstant
.
YG_LIMIT_TTL_QUEUE
,
true
,
false
,
false
,
map
);
}
@Bean
public
DirectExchange
directExchange
(){
return
new
DirectExchange
(
"TTL_EXCHANGE"
);
return
new
DirectExchange
(
RabbitCommonNameConstant
.
OPERATE_COMMON_EXCHANGE
);
}
@Bean
public
Queue
deathQueue
(){
return
new
Queue
(
"DEATH_QUEUE"
);
return
new
Queue
(
RabbitCommonNameConstant
.
YG_LIMIT_DEATH_QUEUE
);
}
@Bean
public
DirectExchange
deathExchange
(){
return
new
DirectExchange
(
"DEATH_EXCHANGE"
);
return
new
DirectExchange
(
RabbitCommonNameConstant
.
DEATH_EXCHANGE
);
}
@Bean
public
Binding
bindingDirect
(){
return
BindingBuilder
.
bind
(
directQueue
()).
to
(
directExchange
()).
with
(
"yg_limit"
);
return
BindingBuilder
.
bind
(
directQueue
()).
to
(
directExchange
()).
with
(
RabbitCommonNameConstant
.
YG_LIMIT_TTL_ROUTE_KEY
);
}
@Bean
public
Binding
bindingDeath
(){
return
BindingBuilder
.
bind
(
deathQueue
()).
to
(
deathExchange
()).
with
(
"death"
);
return
BindingBuilder
.
bind
(
deathQueue
()).
to
(
deathExchange
()).
with
(
RabbitCommonNameConstant
.
YG_LIMIT_DEATH_ROUTE_KEY
);
}
...
...
src/main/java/com/yaoyaozw/customer/constants/RabbitCommonNameConstant.java
0 → 100644
浏览文件 @
c45213f7
package
com
.
yaoyaozw
.
customer
.
constants
;
/**
* @author darker
* @date 2022/10/24 14:40
*/
public
class
RabbitCommonNameConstant
{
/**
* 1、运营系统交换机
*/
public
static
final
String
OPERATE_COMMON_EXCHANGE
=
"OPERATE_COMMON_EXCHANGE"
;
/**
* 阳光访问频率控制
*/
public
static
final
String
YG_LIMIT_TTL_QUEUE
=
"YG_LIMIT_TTL_QUEUE"
;
public
static
final
String
YG_LIMIT_TTL_ROUTE_KEY
=
"YG_LIMIT"
;
/**
* 2、死信交换机 - 死信队列 - routeKey
*/
public
static
final
String
DEATH_EXCHANGE
=
"DEATH_EXCHANGE"
;
/**
* 阳光访问频率死信
*/
public
static
final
String
YG_LIMIT_DEATH_QUEUE
=
"YG_LIMIT_DEATH_QUEUE"
;
public
static
final
String
YG_LIMIT_DEATH_ROUTE_KEY
=
"YG_LIMIT_DEATH"
;
}
src/main/java/com/yaoyaozw/customer/controller/TestController.java
浏览文件 @
c45213f7
...
...
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
import
com.rabbitmq.client.AMQP
;
import
com.rabbitmq.client.Channel
;
import
com.yaoyaozw.customer.constants.CustomerCommonConstant
;
import
com.yaoyaozw.customer.constants.RabbitCommonNameConstant
;
import
com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO
;
import
com.yaoyaozw.customer.service.AccountOrderService
;
import
com.yaoyaozw.customer.service.CustomerDelayPublishService
;
...
...
@@ -105,19 +106,19 @@ public class TestController {
log
.
info
(
"当前count: {}"
,
count
);
long
stamp
=
System
.
currentTimeMillis
();
// 判断计数是否达到上限
go
=
(
Integer
)
count
<
8
0
;
go
=
(
Integer
)
count
<
4
0
;
if
(
go
)
{
// 没有达到上限,发送消息并且计数加1
rabbitTemplate
.
convertAndSend
(
"TTL_EXCHANGE"
,
"yg_limit"
,
stamp
);
rabbitTemplate
.
convertAndSend
(
RabbitCommonNameConstant
.
OPERATE_COMMON_EXCHANGE
,
RabbitCommonNameConstant
.
YG_LIMIT_TTL_ROUTE_KEY
,
stamp
);
redisTemplate
.
opsForValue
().
increment
(
CustomerCommonConstant
.
YANG_GUANG_ACCESS_LIMIT_REDIS_KEY
);
}
}
if
(!
go
)
{
// 计数达到上限了,休眠30秒,递归调用
try
{
log
.
info
(
"达到上限, 休眠1
分钟
"
);
Thread
.
sleep
(
60
000
);
log
.
info
(
"达到上限, 休眠1
5秒
"
);
Thread
.
sleep
(
15
000
);
limit
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
...
...
@@ -126,8 +127,9 @@ public class TestController {
}
@RabbitListener
(
queues
=
"DEATH_QUEUE"
)
@RabbitListener
(
queues
=
RabbitCommonNameConstant
.
YG_LIMIT_DEATH_QUEUE
)
public
void
listener
()
{
log
.
info
(
"消费"
);
redisTemplate
.
opsForValue
().
decrement
(
CustomerCommonConstant
.
YANG_GUANG_ACCESS_LIMIT_REDIS_KEY
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论