How to Deserialising Kafka AVRO messages using Apache Beam

后端 未结 5 2092
一生所求
一生所求 2021-01-15 03:16

The main goal is the aggregate two Kafka topics, one compacted slow moving data and the other fast moving data which is received every second.

I have been able to c

5条回答
  •  悲哀的现实
    2021-01-15 03:46

    I have faced the same issue. Found the solution in this mail-archives. http://mail-archives.apache.org/mod_mbox/beam-user/201710.mbox/%3CCAMsy_NiVrT_9_xfxOtK1inHxb=x_yAdBcBN+4aquu_hn0GJ0nA@mail.gmail.com%3E

    In your case, you need to defined your own KafkaAvroDeserializer like as follows.

    public class MyClassKafkaAvroDeserializer extends
      AbstractKafkaAvroDeserializer implements Deserializer {
    
      @Override
      public void configure(Map configs, boolean isKey) {
          configure(new KafkaAvroDeserializerConfig(configs));
      }
    
      @Override
      public MyClass deserialize(String s, byte[] bytes) {
          return (MyClass) this.deserialize(bytes);
      }
    
      @Override
      public void close() {} }
    

    Then specify your KafkaAvroDeserializer as ValueDeserializer.

    p.apply(KafkaIO.read()
     .withKeyDeserializer(LongDeserializer.class)
     .withValueDeserializer(MyClassKafkaAvroDeserializer.class) );
    

提交回复
热议问题