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
e6ec1125
Commit
e6ec1125
authored
Oct 15, 2024
by
yanzg
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ver1.2' of
http://192.168.0.204/yzg/yzg-util
into ver1.3
parents
d51ffecb
618c2aaa
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
9 deletions
+61
-9
QueueService.java
...rc/main/java/com/yanzuoguang/mq/service/QueueService.java
+6
-0
QueueServiceImpl.java
...ava/com/yanzuoguang/mq/service/impl/QueueServiceImpl.java
+55
-9
No files found.
yzg-util-mq/src/main/java/com/yanzuoguang/mq/service/QueueService.java
View file @
e6ec1125
...
...
@@ -15,4 +15,10 @@ public interface QueueService {
* @param req 保存队列服务
*/
void
create
(
QueueVo
req
);
/**
* 保存接口请求日志
*
* @param req 保存队列服务
*/
void
create
(
QueueVo
req
,
boolean
isAsync
);
}
yzg-util-mq/src/main/java/com/yanzuoguang/mq/service/impl/QueueServiceImpl.java
View file @
e6ec1125
...
...
@@ -4,19 +4,26 @@ import com.yanzuoguang.mq.dao.BeanDao;
import
com.yanzuoguang.mq.service.QueueService
;
import
com.yanzuoguang.mq.vo.QueueVo
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
org.springframework.stereotype.Component
;
import
java.util.Queue
;
import
java.util.concurrent.ConcurrentLinkedQueue
;
/**
* 交换器服务类
*
* @author 颜佐光
*/
@Component
public
class
QueueServiceImpl
implements
QueueService
{
public
class
QueueServiceImpl
implements
QueueService
,
Runnable
{
private
final
BeanDao
beanDao
;
private
final
Queue
<
QueueVo
>
queue
=
new
ConcurrentLinkedQueue
<>();
private
boolean
isAsyncRun
=
false
;
@Autowired
private
BeanDao
beanDao
;
public
QueueServiceImpl
(
BeanDao
beanDao
)
{
this
.
beanDao
=
beanDao
;
}
/**
* 保存接口请求日志
...
...
@@ -26,17 +33,37 @@ public class QueueServiceImpl implements QueueService {
*/
@Override
public
void
create
(
QueueVo
req
)
{
initBean
(
req
);
initBean
(
req
,
true
);
}
@Override
public
void
create
(
QueueVo
req
,
boolean
isAsync
)
{
initBean
(
req
,
isAsync
);
}
/**
* 初始化实体
*
* @param vo 实体相关信息
* @param isAsync 是否异步
*/
private
void
initBean
(
QueueVo
vo
)
{
vo
.
check
();
private
void
initBean
(
QueueVo
vo
,
boolean
isAsync
)
{
if
(!
isAsync
)
{
initBeanHandle
(
vo
);
}
else
{
queue
.
add
(
vo
);
if
(
isAsyncRun
)
{
return
;
}
synchronized
(
this
)
{
isAsyncRun
=
true
;
new
Thread
(
this
).
start
();
}
}
}
private
void
initBeanHandle
(
QueueVo
vo
)
{
vo
.
check
();
// 创建死信队列
if
(!
StringHelper
.
isEmpty
(
vo
.
getDedQueueName
()))
{
beanDao
.
createQueue
(
vo
.
getDedQueueName
());
...
...
@@ -50,7 +77,6 @@ public class QueueServiceImpl implements QueueService {
beanDao
.
createBinding
(
vo
.
getDedExchangeName
(),
vo
.
getDedQueueName
(),
vo
.
getDedRouteKey
());
}
// 创建当前队列,并且绑定死信队列
beanDao
.
createQueue
(
vo
.
getQueueName
(),
vo
.
getDedTime
(),
vo
.
getDedExchangeName
(),
vo
.
getDedRouteKey
());
// 创建当前交换器
...
...
@@ -58,4 +84,24 @@ public class QueueServiceImpl implements QueueService {
// 创建绑定队列
beanDao
.
createBinding
(
vo
.
getExchangeName
(),
vo
.
getQueueName
(),
vo
.
getRouteKey
());
}
@Override
public
void
run
()
{
while
(!
this
.
queue
.
isEmpty
())
{
QueueVo
vo
=
this
.
queue
.
poll
();
try
{
if
(
vo
!=
null
)
{
initBeanHandle
(
vo
);
}
}
catch
(
Exception
ex
)
{
this
.
queue
.
add
(
vo
);
ex
.
printStackTrace
();
ThreadHelper
.
sleep
(
5000
);
}
}
synchronized
(
this
)
{
this
.
isAsyncRun
=
false
;
}
}
}
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