Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
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
项目统一框架
amos-boot-biz
Commits
4407faea
Commit
4407faea
authored
Sep 25, 2023
by
KeYong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
处理冲突
parent
5a11c635
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
22 deletions
+12
-22
KafkaConsumerService.java
.../com/yeejoin/amos/message/kafka/KafkaConsumerService.java
+12
-22
No files found.
amos-boot-utils/amos-boot-utils-message/src/main/java/com/yeejoin/amos/message/kafka/KafkaConsumerService.java
View file @
4407faea
...
...
@@ -28,7 +28,6 @@ public class KafkaConsumerService {
private
static
final
String
MQTT_TOPIC
=
"romaSite/data/transmit"
;
private
static
final
String
MQTT_TOPIC_SHAOSHAN
=
"romaSite/data/shaoshan"
;
private
static
final
String
MQTT_TOPIC
=
"romaSite/data/transmit"
;
private
static
final
String
PROVINCE_MQTT_TOPIC
=
"province/data/transport"
;
@Autowired
protected
EmqKeeper
emqKeeper
;
...
...
@@ -95,6 +94,8 @@ public class KafkaConsumerService {
}
finally
{
ack
.
acknowledge
();
}
}
/**
* 消费单条消息,topics 可以监听多个topic,如:topics = {"topic1", "topic2"}
*
...
...
@@ -123,27 +124,20 @@ public class KafkaConsumerService {
*/
@KafkaListener
(
id
=
"kafkaRoma"
,
groupId
=
"kafkaRoma"
,
topics
=
"#{'${queue.kafka.topics}'.split(',')}"
,
containerFactory
=
"kafkaRomaContainerFactory"
)
public
void
kafkaListener
(
ConsumerRecord
<?,
String
>
record
,
Acknowledgment
ack
)
{
try
{
Optional
<?>
messages
=
Optional
.
ofNullable
(
record
.
value
());
if
(
messages
.
isPresent
())
{
JSONObject
messageObj
=
JSONObject
.
fromObject
(
record
.
value
());
if
(
messageObj
.
getJSONObject
(
BODY
).
isEmpty
())
{
messageObj
.
put
(
DATA_TYPE
,
STATE
);
}
emqKeeper
.
getMqttClient
().
publish
(
MQTT_TOPIC
,
messageObj
.
toString
().
getBytes
(
StandardCharsets
.
UTF_8
),
0
,
false
);
JSONObject
data
=
messageObj
.
getJSONObject
(
"body"
);
if
(
data
.
isEmpty
())
{
data
=
messageObj
;
data
.
put
(
"datatype"
,
"state"
);
try
{
JSONObject
messageObj
=
JSONObject
.
fromObject
(
record
.
value
());
if
(
messageObj
.
getJSONObject
(
BODY
).
isEmpty
())
{
messageObj
.
put
(
DATA_TYPE
,
STATE
);
}
emqKeeper
.
getMqttClient
().
publish
(
MQTT_TOPIC
,
messageObj
.
toString
().
getBytes
(
StandardCharsets
.
UTF_8
),
0
,
false
);
}
catch
(
MqttException
e
)
{
log
.
error
(
"解析数据失败,{}"
,
e
.
getMessage
());
}
finally
{
ack
.
acknowledge
(
);
}
log
.
info
(
"接收到Roma消息对象: {}"
,
data
);
emqKeeper
.
getMqttClient
().
publish
(
MQTT_TOPIC
,
data
.
toString
().
getBytes
(
StandardCharsets
.
UTF_8
),
0
,
false
);
ack
.
acknowledge
();
}
catch
(
MqttException
e
)
{
log
.
error
(
"解析数据失败,{}"
,
e
.
getMessage
());
}
}
}
/**
...
...
@@ -163,10 +157,6 @@ public class KafkaConsumerService {
}
catch
(
MqttException
e
)
{
log
.
error
(
"解析数据失败,{}"
,
e
.
getMessage
());
}
}
catch
(
MqttException
e
)
{
log
.
error
(
"换流站转发Kafka消息失败"
+
e
.
getMessage
(),
e
);
}
finally
{
ack
.
acknowledge
();
}
}
...
...
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