Kafka Join not firing after re-key

烈酒焚心 提交于 2021-02-07 09:44:03

问题


I'm working on a Kafka streams application written in Kotlin, and I'm seeing some bizarre behavior with a join. At a high level, I'm streaming two topics with different keys. However, I can rekey one of the messages so that they keys line up. After I do this though, the subsequent join is not fired. Below I have supplied the simplified code (with irrelevant portions elided and replaced with comments)

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)

When we run this, we see console output from the two peeks that indicate that the messages have been filtered and rekeyed as expected.

We also tried sending the output of the two streams to two similarly partitioned topics right before the join so that we could cat the topic and see what partitions the messages are being written to and with what keys. The results looked fine and are as follows:

Topic One:

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

Topic Two:

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

Is there something I'm missing here? My understanding is that messages with the same key should result in the join firing but that's not what I'm seeing. Thank you for your help!

来源:https://stackoverflow.com/questions/48468832/kafka-join-not-firing-after-re-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!