Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdst
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
1
议题
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdst
提交
7ea297e0
提交
7ea297e0
编写于
8月 22, 2022
作者:
fengmin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mq消息订阅实现5
上级
15afdf4c
变更
1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
18 行增加
和
36 行删除
+18
-36
RocktcermqCustmerRunner.java
.../cn/ibizlab/core/util/config/RocktcermqCustmerRunner.java
+18
-36
未找到文件。
ibzdst-core/src/main/java/cn/ibizlab/core/util/config/RocktcermqCustmerRunner.java
浏览文件 @
7ea297e0
...
...
@@ -19,6 +19,7 @@ import org.springframework.stereotype.Component;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -37,31 +38,32 @@ public class RocktcermqCustmerRunner implements ApplicationRunner {
@Override
public
void
run
(
ApplicationArguments
args
)
{
List
<
RuleEngine
>
ruleEngines
=
ruleEngineMapper
.
selectList
(
new
LambdaQueryWrapper
<
RuleEngine
>().
select
(
RuleEngine:
:
getEngineId
,
RuleEngine:
:
getExtParams
));
List
<
RuleEngine
>
ruleEngines
=
ruleEngineMapper
.
selectList
(
new
LambdaQueryWrapper
<
RuleEngine
>()
.
select
(
RuleEngine:
:
getEngineId
,
RuleEngine:
:
getExtParams
));
if
(!
StringUtils
.
isEmpty
(
ruleEngines
))
{
DefaultMQPushConsumer
consumer
=
null
;
for
(
int
i
=
0
,
len
=
ruleEngines
.
size
();
i
<
len
;
i
++)
{
int
finalI
=
i
;
String
topic
=
getParamTopic
(
ruleEngines
.
get
(
finalI
).
getExtParams
());
if
(
isAutoCreate
(
ruleEngines
.
get
(
finalI
).
getExtParams
())
&&
topic
!=
null
)
{
Map
map
=
getParamMap
(
ruleEngines
.
get
(
i
).
getExtParams
());
if
(
"Y"
.
equals
(
map
.
get
(
"isAuto"
))
&&
!
StringUtils
.
isEmpty
(
map
.
get
(
"topic"
)))
{
log
.
info
(
"ruleEngineConsumer 正在创建---------------------------------------"
);
DefaultMQPushConsumer
consumer
=
new
DefaultMQPushConsumer
(
ruleEngines
.
get
(
finalI
).
getEngineId
());
consumer
=
new
DefaultMQPushConsumer
(
ruleEngines
.
get
(
i
).
getEngineId
());
consumer
.
setNamesrvAddr
(
namesrvAddr
);
consumer
.
setConsumeThreadMin
(
1
);
consumer
.
setConsumeThreadMax
(
1
);
consumer
.
setConsumeMessageBatchMaxSize
(
1
);
// 设置监听
GeneralConsumeMsgListenerProcessor
messageListener
=
new
GeneralConsumeMsgListenerProcessor
(
ruleEngines
.
get
(
finalI
).
getEngineId
());
GeneralConsumeMsgListenerProcessor
messageListener
=
new
GeneralConsumeMsgListenerProcessor
(
ruleEngines
.
get
(
i
).
getEngineId
());
consumer
.
registerMessageListener
(
messageListener
);
consumer
.
setConsumeFromWhere
(
ConsumeFromWhere
.
CONSUME_FROM_FIRST_OFFSET
);
consumer
.
setInstanceName
(
"dstMQMsgConsumer"
);
try
{
consumer
.
subscribe
(
topic
,
"*"
);
consumer
.
subscribe
(
(
String
)
map
.
get
(
"topic"
)
,
"*"
);
consumer
.
start
();
if
(
dataMap
.
get
(
ruleEngines
.
get
(
finalI
))
==
null
)
{
dataMap
.
put
(
ruleEngines
.
get
(
finalI
).
getEngineId
(),
consumer
);
log
.
info
(
"ruleEngineConsumer 创建成功 groupName={}, topics={}, namesrvAddr={}"
,
ruleEngines
.
get
(
finalI
).
getEngineId
(),
ruleEngines
.
get
(
finalI
).
getModelId
(),
namesrvAddr
);
if
(
StringUtils
.
isEmpty
(
dataMap
.
get
(
ruleEngines
.
get
(
i
)))
)
{
dataMap
.
put
(
ruleEngines
.
get
(
i
).
getEngineId
(),
consumer
);
log
.
info
(
"ruleEngineConsumer 创建成功 groupName={}, topics={}, namesrvAddr={}"
,
ruleEngines
.
get
(
i
).
getEngineId
(),
ruleEngines
.
get
(
i
).
getModelId
(),
namesrvAddr
);
}
else
{
log
.
warn
(
"ruleEngineConsumer 不能重复创建 groupName={}, topics={}, namesrvAddr={}"
,
ruleEngines
.
get
(
finalI
).
getEngineId
(),
ruleEngines
.
get
(
finalI
).
getModelId
(),
namesrvAddr
);
log
.
warn
(
"ruleEngineConsumer 不能重复创建 groupName={}, topics={}, namesrvAddr={}"
,
ruleEngines
.
get
(
i
).
getEngineId
(),
ruleEngines
.
get
(
i
).
getModelId
(),
namesrvAddr
);
}
}
catch
(
MQClientException
e
)
{
e
.
printStackTrace
();
...
...
@@ -73,41 +75,21 @@ public class RocktcermqCustmerRunner implements ApplicationRunner {
}
/**
*
判断是否自动创建
*
获取参数map
*
* @param extParams
* @return
*/
public
boolean
isAutoCreate
(
String
extParams
)
{
public
Map
getParamMap
(
String
extParams
)
{
JSONArray
objects
=
JSON
.
parseArray
(
extParams
);
boolean
flat
=
true
;
HashMap
map
=
new
HashMap
()
;
if
(!
CollectionUtils
.
isEmpty
(
objects
))
{
for
(
int
j
=
0
,
len1
=
objects
.
size
();
j
<
len1
;
j
++)
{
String
property
=
objects
.
getJSONObject
(
j
).
getString
(
"property"
);
if
(
"isAuto"
.
equals
(
property
))
{
if
(
"N"
.
equals
(
objects
.
getJSONObject
(
j
).
getString
(
"value"
)))
{
flat
=
false
;
}
break
;
}
map
.
put
(
objects
.
getJSONObject
(
j
).
getString
(
"property"
),
objects
.
getJSONObject
(
j
).
getString
(
"value"
));
}
}
return
flat
;
return
map
;
}
public
String
getParamTopic
(
String
extParams
)
{
JSONArray
objects
=
JSON
.
parseArray
(
extParams
);
boolean
flat
=
true
;
if
(!
CollectionUtils
.
isEmpty
(
objects
))
{
for
(
int
j
=
0
,
len1
=
objects
.
size
();
j
<
len1
;
j
++)
{
String
property
=
objects
.
getJSONObject
(
j
).
getString
(
"property"
);
if
(
"topic"
.
equals
(
property
))
{
return
objects
.
getJSONObject
(
j
).
getString
(
"value"
);
}
}
}
return
null
;
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录