我使用KTable离开了一个KStream,但是我没有看到输出主题的任何输出:
val stringSerde: Serde[String] = Serdes.String()
val longSerde: Serde[java.lang.Long] = Serdes.Long()
val genericRecordSerde: Serde[GenericRecord] = new GenericAvroSerde()
val builder = new KStreamBuilder()
val networkImprStream: KStream[Long, GenericRecord] = builder
.stream(dfpGcsNetworkImprEnhanced)
// Create a global table for advertisers. The data from this global table
// will be fully replicated on each instance of this application.
val advertiserTable: GlobalKTable[java.lang.Long, GenericRecord]= builder.globalTable(advertiserTopicName, "advertiser-store")
// Join the network impr stream to the advertiser global table. As this is global table
// we can use a non-key based join with out needing to repartition the input stream
val networkImprWithAdvertiserNameKStream: KStream[java.lang.Long, GenericRecord] = networkImprStream.leftJoin(advertiserTable,
(_, networkImpr) => {
println(networkImpr)
networkImpr.get("advertiserId").asInstanceOf[java.lang.Long]
},
(networkImpr: GenericRecord, adertiserIdToName: GenericRecord) => {
println(networkImpr)
networkImpr.put("advertiserName", adertiserIdToName.get("name"))
networkImpr
}
)
networkImprWithAdvertiserNameKStream.to(networkImprProcessed)
val streams = new KafkaStreams(builder, streamsConfiguration)
streams.cleanUp()
streams.start()
// usually the stream application would be running forever,
// in this example we just let it run for some time and stop since the input data is finite.
Thread.sleep(15000L)
如果我绕过连接并直接将输入主题输出到输出,我会看到消息到达。我已经将连接更改为左连接,添加了一些printlns来查看提取密钥的时间(虽然控制台上没有打印任何内容)。另外我每次都使用kafka stream reset工具,所以从头开始。我这里的想法已经不多了。此外,我还添加了对商店的一些测试访问权限,它可以工作并包含来自流的密钥(尽管由于左连接,这不应该禁止任何输出)。
答案 0 :(得分:2)
在我的源流中,键为null。虽然我没有使用此密钥加入表,但此密钥不能为空。因此,使用虚拟键创建中间流是有效的。所以,即使我有一个全局KTable,流消息的密钥限制也适用于此: http://docs.confluent.io/current/streams/developer-guide.html#kstream-ktable-join
忽略具有空键或空值的流的输入记录,并且不会触发连接。