Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-kafkaconsumer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 0bed361a
authored
Apr 08, 2022
by
向延琳
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
新增行程数据消费
1 parent
ff171533
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
0 deletions
src/main/java/cn/com/glsx/kafka/config/KafkaConsumerConfig.java
src/main/java/cn/com/glsx/kafka/model/LngLatDTO.java
src/main/java/cn/com/glsx/kafka/protocol/KafkaJourney.java
src/main/java/cn/com/glsx/kafka/queue/consumer/KafkaJourneyConsumer.java
src/main/java/cn/com/glsx/kafka/config/KafkaConsumerConfig.java
View file @
0bed361
...
...
@@ -88,4 +88,13 @@ public class KafkaConsumerConfig {
return
fakeOfficeConsumer
;
}
@Bean
(
initMethod
=
"init"
,
destroyMethod
=
"destroy"
)
KafkaJourneyConsumer
kafkaJourneyConsumer
(
@Value
(
"${mq.kafka.device.journey.topic}"
)
String
topic
)
{
KafkaJourneyConsumer
kafkaJourneyConsumer
=
new
KafkaJourneyConsumer
();
kafkaJourneyConsumer
.
setnThreads
(
nThreads
);
kafkaJourneyConsumer
.
setConsumerConfig
(
gpsConsumerConfig
);
kafkaJourneyConsumer
.
setTopic
(
topic
);
return
kafkaJourneyConsumer
;
}
}
src/main/java/cn/com/glsx/kafka/model/LngLatDTO.java
0 → 100644
View file @
0bed361
package
cn
.
com
.
glsx
.
kafka
.
model
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
/**
* @author xiangyanlin
* @date 2022/4/8
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
public
class
LngLatDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 经度
*/
private
String
lng
;
/**
* 维度
*/
private
String
lat
;
}
src/main/java/cn/com/glsx/kafka/protocol/KafkaJourney.java
0 → 100644
View file @
0bed361
This diff is collapsed.
Click to expand it.
src/main/java/cn/com/glsx/kafka/queue/consumer/KafkaJourneyConsumer.java
0 → 100644
View file @
0bed361
package
cn
.
com
.
glsx
.
kafka
.
queue
.
consumer
;
import
cn.com.glsx.kafka.model.LngLatDTO
;
import
cn.com.glsx.kafka.protocol.KafkaJourney
;
import
cn.com.glsx.kafka.queue.base.MessageReceiver
;
import
cn.com.glsx.stdinterface.api.JourneyClient
;
import
cn.com.glsx.stdinterface.dto.DeviceJourneyDTO
;
import
com.alibaba.fastjson.JSON
;
import
com.glsx.plat.common.utils.DateUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
/**
* 行程数据消费
* @author xiangyanlin
* @date 2022/4/7
*/
@Slf4j
public
class
KafkaJourneyConsumer
extends
MessageReceiver
{
@Qualifier
(
"cn.com.glsx.stdinterface.api.JourneyClient"
)
@Autowired
private
JourneyClient
journeyClient
;
@Override
public
void
processMessage
(
String
topic
,
byte
[]
message
)
throws
Exception
{
KafkaJourney
.
neshield_journey_req
journey
=
KafkaJourney
.
neshield_journey_req
.
parseFrom
(
message
);
log
.
info
(
"设备行程:{}"
+
journey
.
toString
());
//保存行程信息 里程信息
journeyClient
.
saveDeviceJourney
(
convert
(
journey
));
}
/**
* 转为保存需要的实体
*/
public
DeviceJourneyDTO
convert
(
KafkaJourney
.
neshield_journey_req
journey
)
{
DeviceJourneyDTO
deviceJourneyDTO
=
new
DeviceJourneyDTO
();
deviceJourneyDTO
.
setSn
(
journey
.
getSn
());
deviceJourneyDTO
.
setBeginTime
(
DateUtils
.
stringToDate
(
journey
.
getBeginTime
(),
DateUtils
.
NORMAL_DATE_TIME_PATTERN
));
deviceJourneyDTO
.
setEndTime
(
DateUtils
.
stringToDate
(
journey
.
getEndTime
(),
DateUtils
.
NORMAL_DATE_TIME_PATTERN
));
deviceJourneyDTO
.
setBeginAddress
(
JSON
.
toJSONString
(
new
LngLatDTO
(
journey
.
getBeginLng
(),
journey
.
getBeginLat
())));
deviceJourneyDTO
.
setEndAddress
(
JSON
.
toJSONString
(
new
LngLatDTO
(
journey
.
getEndLng
(),
journey
.
getEndLat
())));
deviceJourneyDTO
.
setMileage
(
journey
.
getMileage
());
return
deviceJourneyDTO
;
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment