无法获取已加入的Kafka流来运行或输出任何内容

时间:2016-08-04 15:37:22

标签: java scala apache-kafka apache-kafka-streams

对于下面的代码,stream1和stream2都可以单独运行,我可以看到输出,但是连接的流根本不记录任何内容。我觉得它与连接窗口有关,但来自两个流的数据几乎完全同时出现。

val stream = builder.stream(stringSerde, byteArraySerde, "topic")

val stream1 = stream
  .filter((key, value) => somefilter(key, value))
  .through(stringSerde, byteArraySerde, "topic1")

val stream2 = stream
  .filter((key, value) => someotherfilter(key, value))
  .through(stringSerde, byteArraySerde, "topic2")

val joinedStream = stream1
  .join(stream2, (value1: Array[Byte], value2: Array[Byte]) => {
    println("wont print anything")
    return somerandomdata
  },
  JoinWindows.of("othertopic").within(10000L),
  stringSerde, byteArraySerde, byteArraySerde)

1 个答案:

答案 0 :(得分:0)

两个主题的密钥不应该相同才能加入吗?

我认为Javadoc解释了这一点: https://kafka.apache.org/0102/javadoc/org/apache/kafka/streams/kstream/JoinWindows.html

这也许是一个有趣的读物: https://cwiki.apache.org/confluence/display/KAFKA/Kafka+Streams+Join+Semantics