简体   繁体   English

以 avro 格式使用来自 apache kafka 的消息

[英]Consuming messages from apache kafka in avro format

I want to consume messages from my Kafka broker using a spring boot configured consumer using the spring-Kafka library, the source is a JDBC connector which is responsible for pulling messages from a MySQL database and these messages need to be consumed我想使用spring-Kafka库使用spring boot配置的消费者来消费来自我的Kafka代理的消息,源是一个JDBC连接器,它负责从MySQL数据库中提取消息,这些消息需要被消费

Below I am attaching my application.yml file下面我附上我的 application.yml 文件

server:
  port: 9000
spring:
  kafka:
    consumer:
      bootstrap-servers: localhost:9092
      group-id: group_id
      auto-offset-reset: earliest
      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
    producer:
      bootstrap-servers: localhost:9092
      key-serializer: org.apache.kafka.common.serialization.StringSerializer
      value-serializer: org.apache.kafka.common.serialization.StringSerializer

Consumer -消费者 -

  @KafkaListener(topics = "Sample-Topic", groupId = "group_id")
    public void consume(String message) throws IOException {
        System.out.println(message);
    }

Messages in topics are stored in Avro format as I am using JDBC connector.当我使用 JDBC 连接器时,主题中的消息以 Avro 格式存储。

Instead of the JSON, I am getting encrypted output and some of the output messages are only plain strings.我得到的不是 JSON,而是加密输出,并且一些输出消息只是纯字符串。

您需要使用 avro deserializer 而不是StringDeserializer

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

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