Kafka加入后没有开火

时间:2018-01-26 20:10:16

标签: kotlin apache-kafka apache-kafka-streams

我正在开发一个用Kotlin编写的Kafka流应用程序,我看到了一些奇怪的加入行为。在较高的层面上,我使用不同的密钥传输两个主题。但是,我可以重新输入其中一条消息,以便它们按键排列。我执行此操作后,不会触发后续连接。下面我提供了简化代码(不相关部分省略并替换为注释)

val builder = KStreamBuilder()
val joinWindow = JoinWindows.of(/* 30 days */).until(/* 365 days */)

val topicOneStream = builder.stream<String, String>(topicOne)
val reKeyedTopicOneStream = topicOneStream.filter({ key, value ->
        // ... some logic to filter messages here
}).selectKey({ _, value ->
        // Rekey messages here based on the signature (which will match the key from corresponding messages on topicTwo)
        JSON.parseMessage(value)?.data?.authorization?.data?.signature
}).peek({ key, value -> logger.info("post-topicOne-filter $key, $value")})

val topicTwoStream = builder.stream<String, String>(topicTwo)
val filteredTopicTwoStream = topicTwoStream.filter({ key, value ->
        // ... other filtering logic goes here
        // these keys match those of the re-keyed messages from topic one
}).peek({ key, value -> logger.info("post-hello-sign event filter: $key, $value")})

val joinedStream = reKeyedTopicOneStream.join(filteredTopicTwoStream, { _, _  ->
    // Doesn't fire... sometimes
}, joinWindow)

当我们运行它时,我们会看到两个peek中的控制台输出,表明消息已经过滤并按预期重新加密。

我们还尝试在连接之前将两个流的输出发送到两个相似的分区主题,以便我们可以捕获主题并查看正在写入消息的分区以及使用哪些键。结果看起来很好,如下:

主题一:

Message with key 7e7f4e74-fc5e-4676-893a-353e4fb217f6 at partition 1 at offset 0

主题二:

Message with key 7e7f4e74-fc5e-4676-893a-353e4fb217f6 at partition 1 at offset 0

这里有什么我想念的吗?我的理解是,具有相同键的消息应该导致连接触发,但这不是我所看到的。谢谢你的帮助!

0 个答案:

没有答案