【问题标题】:"Malformed data. Length is negative" while deserializing avro class反序列化 avro 类时出现“格式错误的数据。长度为负数”
【发布时间】:2017-07-08 18:49:48
【问题描述】:

我使用带有 avro 序列化的 kafka: http://docs.spring.io/spring-cloud-stream/docs/current-SNAPSHOT/reference/htmlsingle/#_avro_schema_registry_client_message_converters

我在本地模式注册表中注册了模式,并将 ed@EnableSchemaRegistryClient 添加到我的应用程序中,并在 application.yml 中设置:

spring:
  cloud:
    stream:
      bindings:
        output:
          destination: output
        input:
          destination: topicName
          contentType: application/*+avro
      schemaRegistryClient:
        endpoint: http://127.0.0.1:8081

我还使用avro-tools-1.8.1.jar 生成了类。现在我正在尝试读取和转换来自 kafka 的消息:

  @StreamListener(Sink.INPUT)
  public void handlePublish(MyClass message) throws IOException {
    logger.info("Receiving MyClass" + message);
  }

但转换器失败:org.apache.avro.AvroRuntimeException: Malformed data. Length is negative

堆栈跟踪:

 org.springframework.messaging.MessagingException: Exception thrown while invoking kafka.Consumer#handlePublish[1 args]; nested exception is org.apache.avro.AvroRuntimeException: Malformed data. Length is negative: -62
    at org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor$StreamListenerMessageHandler.handleRequestMessage(StreamListenerAnnotationBeanPostProcessor.java:364) ~[spring-cloud-stream-1.1.1.RELEASE.jar:1.1.1.RELEASE]
    ....
Caused by: org.apache.avro.AvroRuntimeException: Malformed data. Length is negative: -62
at org.apache.avro.io.BinaryDecoder.doReadBytes(BinaryDecoder.java:336) ~[avro-1.8.1.jar:1.8.1]
...at org.springframework.cloud.stream.schema.avro.AbstractAvroMessageConverter.convertFromInternal(AbstractAvroMessageConverter.java:91) ~[spring-cloud-stream-schema-1.1.1.RELEASE.jar:1.1.1.RELEASE]
    at org.springframework.messaging.converter.AbstractMessageConverter.fromMessage(AbstractMessageConverter.java:175) ~[spring-messaging-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.messaging.converter.CompositeMessageConverter.fromMessage(CompositeMessageConverter.java:67) ~[spring-messaging-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver.resolveArgument(PayloadArgumentResolver.java:117) ~[spring-messaging-4.3.4.RELEASE.jar:4.3.4.RELEASE]
....

【问题讨论】:

标签: java spring apache-kafka avro spring-cloud-stream


【解决方案1】:

我注意到你上面使用的属性是spring.cloud.schemaRegistryClient,但它必须是spring.cloud.stream.schemaRegistryClient

【讨论】:

    猜你喜欢
    • 2021-10-29
    • 1970-01-01
    • 2019-09-11
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 2018-07-01
    • 2013-12-18
    • 1970-01-01
    相关资源
    最近更新 更多