Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
O
operate-customer-service
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
沈振路
operate-customer-service
Commits
80b3fffb
提交
80b3fffb
authored
10月 24, 2022
作者:
沈振路
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
频率控制
上级
a1e6598d
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
72 行增加
和
6 行删除
+72
-6
pom.xml
pom.xml
+2
-2
RabbitConfig.java
...main/java/com/yaoyaozw/customer/configs/RabbitConfig.java
+7
-3
TestController.java
...java/com/yaoyaozw/customer/controller/TestController.java
+62
-0
bootstrap.yml
src/main/resources/bootstrap.yml
+1
-1
没有找到文件。
pom.xml
浏览文件 @
80b3fffb
...
@@ -224,10 +224,10 @@
...
@@ -224,10 +224,10 @@
<artifactId>
spring-cloud-starter-netflix-hystrix
</artifactId>
<artifactId>
spring-cloud-starter-netflix-hystrix
</artifactId>
</dependency>
</dependency>
<!--
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-amqp
</artifactId>
<artifactId>
spring-boot-starter-amqp
</artifactId>
</dependency>
-->
</dependency>
<dependency>
<dependency>
...
...
src/main/java/com/yaoyaozw/customer/configs/RabbitConfig.java
浏览文件 @
80b3fffb
package
com
.
yaoyaozw
.
customer
.
configs
;
package
com
.
yaoyaozw
.
customer
.
configs
;
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.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -10,10 +14,10 @@ import java.util.Map;
...
@@ -10,10 +14,10 @@ import java.util.Map;
* @author darker
* @author darker
* @date 2022/10/21 16:04
* @date 2022/10/21 16:04
*/
*/
//
@Configuration
@Configuration
public
class
RabbitConfig
{
public
class
RabbitConfig
{
/*
@Bean
@Bean
public
Queue
directQueue
(){
public
Queue
directQueue
(){
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
4
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
4
);
map
.
put
(
"x-dead-letter-exchange"
,
"DEATH_EXCHANGE"
);
map
.
put
(
"x-dead-letter-exchange"
,
"DEATH_EXCHANGE"
);
...
@@ -45,7 +49,7 @@ public class RabbitConfig {
...
@@ -45,7 +49,7 @@ public class RabbitConfig {
@Bean
@Bean
public
Binding
bindingDeath
(){
public
Binding
bindingDeath
(){
return
BindingBuilder
.
bind
(
deathQueue
()).
to
(
deathExchange
()).
with
(
"death"
);
return
BindingBuilder
.
bind
(
deathQueue
()).
to
(
deathExchange
()).
with
(
"death"
);
}
*/
}
}
}
src/main/java/com/yaoyaozw/customer/controller/TestController.java
浏览文件 @
80b3fffb
package
com
.
yaoyaozw
.
customer
.
controller
;
package
com
.
yaoyaozw
.
customer
.
controller
;
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.dto.integration.IntegrationRequestDTO
;
import
com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO
;
import
com.yaoyaozw.customer.service.AccountOrderService
;
import
com.yaoyaozw.customer.service.AccountOrderService
;
import
com.yaoyaozw.customer.service.CustomerDelayPublishService
;
import
com.yaoyaozw.customer.service.CustomerDelayPublishService
;
import
com.yaoyaozw.customer.service.CustomerGraphicsService
;
import
com.yaoyaozw.customer.service.CustomerGraphicsService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.amqp.rabbit.core.ChannelCallback
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
...
@@ -15,6 +24,7 @@ import java.util.Calendar;
...
@@ -15,6 +24,7 @@ import java.util.Calendar;
* @author wgh
* @author wgh
* @date 2022/10/10 20:04
* @date 2022/10/10 20:04
*/
*/
@Slf4j
@RestController
@RestController
@RequestMapping
(
"/customer-service/test"
)
@RequestMapping
(
"/customer-service/test"
)
public
class
TestController
{
public
class
TestController
{
...
@@ -25,6 +35,10 @@ public class TestController {
...
@@ -25,6 +35,10 @@ public class TestController {
private
AccountOrderService
accountOrderService
;
private
AccountOrderService
accountOrderService
;
@Autowired
@Autowired
private
CustomerDelayPublishService
customerDelayPublishService
;
private
CustomerDelayPublishService
customerDelayPublishService
;
@Autowired
private
RabbitTemplate
rabbitTemplate
;
@Autowired
private
RedisTemplate
<
String
,
Object
>
redisTemplate
;
@GetMapping
(
"/CustomerTest"
)
@GetMapping
(
"/CustomerTest"
)
public
void
test
(){
public
void
test
(){
...
@@ -69,4 +83,52 @@ public class TestController {
...
@@ -69,4 +83,52 @@ public class TestController {
integrationRequestDTO
.
setRequestDate
(
calendar
.
getTime
());
integrationRequestDTO
.
setRequestDate
(
calendar
.
getTime
());
accountOrderService
.
activeUserByOrder
(
integrationRequestDTO
);
accountOrderService
.
activeUserByOrder
(
integrationRequestDTO
);
}
}
@GetMapping
(
"/ygLimit"
)
public
void
ygLimit
(){
limit
();
}
private
void
limit
()
{
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
;
}
log
.
info
(
"当前count: {}"
,
count
);
long
stamp
=
System
.
currentTimeMillis
();
// 判断计数是否达到上限
go
=
(
Integer
)
count
<
80
;
if
(
go
)
{
// 没有达到上限,发送消息并且计数加1
rabbitTemplate
.
convertAndSend
(
"TTL_EXCHANGE"
,
"yg_limit"
,
stamp
);
redisTemplate
.
opsForValue
().
increment
(
CustomerCommonConstant
.
YANG_GUANG_ACCESS_LIMIT_REDIS_KEY
);
}
}
if
(!
go
)
{
// 计数达到上限了,休眠30秒,递归调用
try
{
log
.
info
(
"达到上限, 休眠30秒"
);
Thread
.
sleep
(
30000
);
limit
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
@RabbitListener
(
queues
=
"DEATH_QUEUE"
)
public
void
listener
()
{
redisTemplate
.
opsForValue
().
decrement
(
CustomerCommonConstant
.
YANG_GUANG_ACCESS_LIMIT_REDIS_KEY
);
}
}
}
src/main/resources/bootstrap.yml
浏览文件 @
80b3fffb
...
@@ -4,7 +4,7 @@ spring:
...
@@ -4,7 +4,7 @@ spring:
application
:
application
:
name
:
customer-service
name
:
customer-service
profiles
:
profiles
:
active
:
pro
active
:
dev
---
---
spring
:
spring
:
profiles
:
dev
profiles
:
dev
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论