首页 > 解决方案 > Confluent Kafka Avro 序列化器和 Spring Cloud

问题描述

我正在尝试使用 Spring Cloud 和 Kafka Avro Serializer 在 Kafka 上生成一个事件。

在我的 application.yml 中,我有以下配置,但是当 Serializer 尝试生成消息时,它生成为字节,因为传递给 KafkaSerializer 中的 getScheme 方法的对象是字节数组,它不是 GenericRecord。我认为我需要 Spring Cloud 中的特定 MessageConverter,但我没有找到。

cloud:
stream:
  kafka:
    binder:
      brokers:
        - 'localhost:9092'
      useNativeDecoding: true
    bindings:
      Ptr-output:
          producer:
            configuration:
              schema.registry.url: 'http://localhost:8081'
              key.serializer: org.apache.kafka.common.serialization.StringSerializer
              value.serializer: com.abc.message.ptr.KafkaSerializer
  schemaRegistryClient:
    endpoint: 'http://localhost:8081'
  bindings:
     Ptr-output:
      contentType: application/*+avro
      destination: Ptr
  schema:
    avro:
      schema-locations: 'classpath:avro/Ptr.avsc'
      dynamic-schema-generation-enabled: false

我能怎么做?我该如何解决?

标签: apache-kafkaspring-cloudavrospring-cloud-streamconfluent-platform

解决方案


尝试将序列化程序设置为io.confluent.kafka.serializers.KafkaAvroDeserializer


推荐阅读