簡體   English   中英

“格式錯誤的數據。 長度為負數”時反序列化Avro類

[英]“Malformed data. Length is negative” while deserializing avro class

我將kafka與avro序列化一起使用: http ://docs.spring.io/spring-cloud-stream/docs/current-SNAPSHOT/reference/htmlsingle/#_avro_schema_registry_client_message_converters

我在本地schema-registry中注冊了schema,並使用application.yml中的設置將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 negativeorg.apache.avro.AvroRuntimeException: Malformed data. Length is negative 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]
....

我注意到您上面使用的屬性是spring.cloud.schemaRegistryClient但它必須是spring.cloud.stream.schemaRegistryClient

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM