简体   繁体   English

kafka流到ktable加入

[英]kafka stream to ktable join

I am trying to join a 我正在尝试加入

  • KStream: created from a topic, the topic has JSON value. KStream:从一个主题创建,该主题具有JSON值。 I re-key the stream using two attributed from the value. 我使用值中的两个属性来重新设置流。 example value (snippet of the json). 示例值(json的片段)。 I created a custom pojo class and use a custom serdes. 我创建了一个自定义pojo类,并使用了一个自定义serdes。 {"value":"0","time":1.540753118800291E9,,"deviceIp":"111.111.111.111","deviceName":"KYZ1","indicatorName":"ifHCInOctets"}

keys are mapped as: 键映射为:

map((key, value) -> KeyValue.pair(value.deviceName+value.indicatorName, value))

I do a peek on the KStream and prints both key and the attributes I used. 我在KStream上进行了窥视,并打印了我使用的键和属性。 Looks all good. 看起来都不错。

  • KTable: I create a ktable from a topic, I am writing to the topic using a python script and the key for the topic is KYZ1ifHCInOctets , the combination of device name and indicator name (from above). KTable:我从一个主题创建一个ktable,我正在使用python脚本写入该主题,该主题的键是KYZ1ifHCInOctets ,即设备名称和指标名称的组合(从上面)。 I do a toStream and then a peek on the resulting stream. 我执行了toStream,然后浏览了生成的流。 Keys and values all seems fine. 键和值似乎都很好。

Now when i do a inner join and do a peek or through/to a topic i see the key and values are mismatched. 现在,当我进行内部联接并进行窥视或遍历某个主题时,我会看到键和值不匹配。 Join doesn't seems to work, 加入似乎无效,

  KStream<String, MyPojoClass> joined= datastream.join(table, 
          (data,table)->data
          ,Joined.with(Serdes.String(),myCustomSerde,Serdes.String())
          );

key = XYZ1s1_TotalDiscards
Value = {"deviceName":"ABC2", "indicatorName":"jnxCosQstatTxedBytes"}

I have the exactly the same thing working through ksql, but wanted to do my own stream app. 我在通过ksql进行工作时完全一样,但是想做自己的流应用程序。

现在,对于错误的根源听起来如此愚蠢,我的PoJo类几乎没有什么静态的属性:-(,导致了错误的键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM