在风暴拓扑中存储中间数据

时间:2018-05-28 08:36:50

标签: java apache-storm trident

我正在阅读2个kafka主题的数据。这可以描述为:

Topic1 data content: VehicleRegistrationNo, Timestamp, Location Topic2 data content: VehicleRegistrationNo, Timestamp, Speed

我需要根据两者中最接近的时间戳合并这两条消息,并输出元组作为消息VehicleRegistrationNo, Timestamp, Speed, Location。我正在通过2个spout S1S2阅读这些主题。然后,螺栓MergeS1andS2从这些喷口获取输入,并按以下方式工作:

if (message from S1): save present message from S1 along with 2 previous messages (3 consecutive locations) to LocationHashMap elseif (message from S2): get locations details from LocationHashmap and merge speed for same Vehicle with location info, then send details to next bolt as tuple

我知道HashMap不是在多节点中存储数据的有效方式。所以我读到了Trident和Redis来存储中间数据。我应该使用什么方法将我的中间数据存储在这个可以在分布式拓扑中工作的senario中。

1 个答案:

答案 0 :(得分:0)

任何no-sql数据库都可以解决问题。选择一个唯一标识元组的键,无论来自哪个主题。逻辑将是这样的:

  • 尝试从数据库中查找元组。
  • 如果数据库中不存在元组,则将从主题中获取的元组存储到数据库中。
  • 如果存在元组,则合并数据库元组和主题元组的内容,并将生成的元组存储回数据库(覆盖数据库中前一元组的内容)
相关问题