|
7 | 7 | import org.apache.kafka.streams.KafkaStreams.StateListener;
|
8 | 8 | import org.apache.kafka.streams.errors.StreamsUncaughtExceptionHandler;
|
9 | 9 |
|
10 |
| -import us.dot.its.jpo.deduplicator.deduplicator.serialization.JsonSerdes; |
11 | 10 | import us.dot.its.jpo.geojsonconverter.DateJsonMapper;
|
| 11 | +import us.dot.its.jpo.ode.model.OdeTimData; |
| 12 | +import us.dot.its.jpo.ode.model.OdeTimMetadata; |
| 13 | +import us.dot.its.jpo.ode.model.OdeTimPayload; |
| 14 | +import us.dot.its.jpo.ode.plugin.j2735.OdeTravelerInformationMessage; |
| 15 | +import us.dot.its.jpo.ode.plugin.j2735.travelerinformation.TravelerInformation; |
12 | 16 |
|
13 | 17 | import org.apache.kafka.streams.kstream.*;
|
14 | 18 | import org.apache.kafka.streams.state.Stores;
|
|
23 | 27 |
|
24 | 28 | import us.dot.its.jpo.deduplicator.DeduplicatorProperties;
|
25 | 29 | import us.dot.its.jpo.deduplicator.deduplicator.processors.suppliers.OdeTimJsonProcessorSupplier;
|
| 30 | +import us.dot.its.jpo.deduplicator.deduplicator.serialization.JsonSerdes; |
26 | 31 |
|
27 | 32 |
|
28 | 33 | public class TimDeduplicatorTopology {
|
@@ -65,37 +70,34 @@ public JsonNode genJsonNode() {
|
65 | 70 | public Topology buildTopology() {
|
66 | 71 | StreamsBuilder builder = new StreamsBuilder();
|
67 | 72 |
|
68 |
| - KStream<Void, JsonNode> inputStream = builder.stream(props.getKafkaTopicOdeTimJson(), |
69 |
| - Consumed.with(Serdes.Void(), JsonSerdes.JSON())); |
| 73 | + KStream<String, OdeTimData> inputStream = builder.stream(props.getKafkaTopicOdeTimJson(), |
| 74 | + Consumed.with(Serdes.String(), JsonSerdes.OdeTim())); |
70 | 75 |
|
71 | 76 | builder.addStateStore(Stores.keyValueStoreBuilder(Stores.persistentKeyValueStore(props.getKafkaStateStoreOdeTimJsonName()),
|
72 |
| - Serdes.String(), JsonSerdes.JSON())); |
| 77 | + Serdes.String(), JsonSerdes.OdeTim())); |
73 | 78 |
|
74 |
| - |
75 |
| - |
76 |
| - KStream<String, JsonNode> timRekeyedStream = inputStream.selectKey((key, value) -> { |
| 79 | + KStream<String, OdeTimData> timRekeyedStream = inputStream.selectKey((key, value) -> { |
77 | 80 | try {
|
78 |
| - |
79 |
| - JsonNode travellerInformation = value.get("payload") |
80 |
| - .get("data") |
81 |
| - .get("MessageFrame") |
82 |
| - .get("value") |
83 |
| - .get("TravelerInformation"); |
84 | 81 |
|
85 |
| - String rsuIP = value.get("metadata").get("originIp").asText(); |
86 |
| - String packetId = travellerInformation.get("packetID").asText(); |
87 |
| - String msgCnt = travellerInformation.get("msgCnt").asText(); |
| 82 | + TravelerInformation travellerInformation = (TravelerInformation)value.getPayload().getData(); |
| 83 | + |
| 84 | + |
| 85 | + String rsuIP = ((OdeTimMetadata)value.getMetadata()).getOriginIp(); |
| 86 | + // String packetId = ((OdeTimPayload)value.getPayload()).getData();// .get("packetID").asText(); |
| 87 | + String packetId = travellerInformation.getPacketID().toString(); |
| 88 | + int msgCnt = travellerInformation.getMsgCnt().intValue(); |
88 | 89 |
|
89 | 90 | String newKey = rsuIP + "_" + packetId + "_" + msgCnt;
|
90 | 91 | return newKey;
|
91 | 92 | } catch (Exception e) {
|
| 93 | + System.out.println(e); |
92 | 94 | return "";
|
93 | 95 | }
|
94 |
| - }).repartition(Repartitioned.with(Serdes.String(), JsonSerdes.JSON())); |
| 96 | + }).repartition(Repartitioned.with(Serdes.String(), JsonSerdes.OdeTim())); |
95 | 97 |
|
96 |
| - KStream<String, JsonNode> deduplicatedStream = timRekeyedStream.process(new OdeTimJsonProcessorSupplier(props), props.getKafkaStateStoreOdeTimJsonName()); |
| 98 | + KStream<String, OdeTimData> deduplicatedStream = timRekeyedStream.process(new OdeTimJsonProcessorSupplier(props), props.getKafkaStateStoreOdeTimJsonName()); |
97 | 99 |
|
98 |
| - deduplicatedStream.to(props.getKafkaTopicDeduplicatedOdeTimJson(), Produced.with(Serdes.String(), JsonSerdes.JSON())); |
| 100 | + deduplicatedStream.to(props.getKafkaTopicDeduplicatedOdeTimJson(), Produced.with(Serdes.String(), JsonSerdes.OdeTim())); |
99 | 101 |
|
100 | 102 | return builder.build();
|
101 | 103 |
|
|
0 commit comments