【问题标题】:storing intermediate data in storm topology在风暴拓扑中存储中间数据
【发布时间】:2018-05-28 08:36:49
【问题描述】:

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

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

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

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 来存储中间数据。我应该使用什么来将我的中间数据存储在这个可以在分布式拓扑中工作的场景中。

【问题讨论】:

    标签: java apache-storm trident


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-06
      • 1970-01-01
      • 2016-08-21
      • 1970-01-01
      • 1970-01-01
      • 2018-06-09
      • 2018-07-19
      • 2018-10-15
      相关资源
      最近更新 更多