Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
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
YZG
yzg-util
Commits
cbdb67fa
Commit
cbdb67fa
authored
Aug 31, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改MQ请求尸体,防止出错
parent
4ef6aeb0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
8 deletions
+61
-8
StringHelper.java
...c/main/java/com/yanzuoguang/util/helper/StringHelper.java
+14
-0
YzgMqConsumer.java
.../src/main/java/com/yanzuoguang/mq/plan/YzgMqConsumer.java
+47
-2
MqServiceImpl.java
...n/java/com/yanzuoguang/mq/service/impl/MqServiceImpl.java
+0
-6
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/StringHelper.java
View file @
cbdb67fa
...
...
@@ -798,6 +798,20 @@ public class StringHelper {
return
0
;
}
/**
* 计算分页数量
*
* @param count 数据条数
* @param size 每页大小
* @return
*/
public
static
long
getPage
(
long
count
,
long
size
)
{
if
(
size
!=
0
)
{
return
count
/
size
+
(
count
%
size
>
0
?
1
:
0
);
}
return
0
;
}
/**
* 将字符串转换为菜单
*
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/plan/YzgMqConsumer.java
View file @
cbdb67fa
...
...
@@ -3,15 +3,20 @@ package com.yanzuoguang.mq.plan;
import
com.rabbitmq.client.Channel
;
import
com.yanzuoguang.mq.service.MqService
;
import
com.yanzuoguang.mq.vo.MessageVo
;
import
com.yanzuoguang.mq.vo.QueueVo
;
import
com.yanzuoguang.mq.vo.req.RegisterServerTokenReqVo
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.log.Log
;
import
org.springframework.amqp.core.Message
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 评论模块消息队列处理
*
...
...
@@ -20,6 +25,16 @@ import org.springframework.stereotype.Component;
@Component
public
class
YzgMqConsumer
{
private
static
class
TimeUnit
{
public
String
tag
;
public
long
unit
;
public
TimeUnit
(
String
tag
,
long
unit
)
{
this
.
tag
=
tag
;
this
.
unit
=
unit
;
}
}
/**
* 延迟队列
*/
...
...
@@ -27,7 +42,14 @@ public class YzgMqConsumer {
/**
* 默认100天延迟
*/
public
static
final
long
YZG_MQ_SYSTEM_QUEUE_DELAY_TIME
=
1000
;
public
static
final
TimeUnit
[]
YZG_MQ_SYSTEM_QUEUE_DELAY_TIME
=
new
TimeUnit
[]{
new
TimeUnit
(
"MillSecond"
,
1
),
new
TimeUnit
(
"Second"
,
1000
),
new
TimeUnit
(
"Minute"
,
1000
*
60
),
new
TimeUnit
(
"Hour"
,
1000
*
60
*
60
),
new
TimeUnit
(
"Day"
,
1000
*
60
*
60
*
24
),
new
TimeUnit
(
"Year"
,
1000
*
60
*
60
*
24
*
365
)
};
/**
* 执行的消息队列
*/
...
...
@@ -42,6 +64,8 @@ public class YzgMqConsumer {
@Autowired
private
MqService
mqService
;
private
Map
<
String
,
Boolean
>
cacheQueueName
=
new
HashMap
<>();
/**
* MQ回调
*
...
...
@@ -84,7 +108,28 @@ public class YzgMqConsumer {
*/
public
String
sendDelay
(
String
json
,
long
dedTime
)
{
if
(
dedTime
>
0
)
{
return
mqService
.
message
(
new
MessageVo
(
YZG_MQ_SYSTEM_QUEUE_DELAY
,
YZG_MQ_SYSTEM_QUEUE_DELAY
,
json
,
dedTime
));
TimeUnit
timeUnit
=
YZG_MQ_SYSTEM_QUEUE_DELAY_TIME
[
0
];
for
(
int
i
=
YZG_MQ_SYSTEM_QUEUE_DELAY_TIME
.
length
-
1
;
i
>=
0
;
i
--)
{
timeUnit
=
YZG_MQ_SYSTEM_QUEUE_DELAY_TIME
[
i
];
if
(
dedTime
>
timeUnit
.
unit
)
{
break
;
}
}
long
count
=
StringHelper
.
getPage
(
dedTime
,
timeUnit
.
unit
);
String
mqName
=
StringHelper
.
getId
(
YzgMqConsumer
.
YZG_MQ_SYSTEM_QUEUE_DELAY
,
timeUnit
.
tag
,
count
);
boolean
is
=
StringHelper
.
toBoolean
(
cacheQueueName
.
get
(
mqName
));
if
(!
is
)
{
synchronized
(
cacheQueueName
)
{
is
=
StringHelper
.
toBoolean
(
cacheQueueName
.
get
(
mqName
));
if
(!
is
)
{
QueueVo
queueVo
=
new
QueueVo
(
mqName
,
count
*
timeUnit
.
unit
,
YzgMqConsumer
.
YZG_MQ_SYSTEM_QUEUE
);
queueVo
.
check
();
mqService
.
createQueue
(
queueVo
);
}
}
}
return
mqService
.
message
(
new
MessageVo
(
mqName
,
json
,
dedTime
));
}
else
{
return
mqService
.
message
(
new
MessageVo
(
YZG_MQ_SYSTEM_QUEUE
,
YZG_MQ_SYSTEM_QUEUE
,
json
));
}
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/service/impl/MqServiceImpl.java
View file @
cbdb67fa
...
...
@@ -79,12 +79,6 @@ public class MqServiceImpl implements MqService, InitializingBean {
}
this
.
localName
=
UrlHelper
.
getIp
();
QueueVo
queueVo
=
new
QueueVo
(
YzgMqConsumer
.
YZG_MQ_SYSTEM_QUEUE_DELAY
,
YzgMqConsumer
.
YZG_MQ_SYSTEM_QUEUE_DELAY
,
YzgMqConsumer
.
YZG_MQ_SYSTEM_QUEUE_DELAY
,
YzgMqConsumer
.
YZG_MQ_SYSTEM_QUEUE_DELAY_TIME
,
YzgMqConsumer
.
YZG_MQ_SYSTEM_QUEUE
,
YzgMqConsumer
.
YZG_MQ_SYSTEM_QUEUE
,
YzgMqConsumer
.
YZG_MQ_SYSTEM_QUEUE
);
queueVo
.
check
();
queueService
.
create
(
queueVo
);
QueueVo
removeToken
=
new
QueueVo
(
YzgMqConsumer
.
YZG_MQ_CLEAR_TOKEN_QUEUE
,
YzgMqConsumer
.
YZG_MQ_CLEAR_TOKEN_QUEUE
,
YzgMqConsumer
.
YZG_MQ_CLEAR_TOKEN_QUEUE
);
removeToken
.
check
();
queueService
.
create
(
removeToken
);
...
...
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