Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java &引用;格式错误的数据。长度为负”;反序列化avro类时_Java_Spring_Apache Kafka_Avro_Spring Cloud Stream - Fatal编程技术网

Java &引用;格式错误的数据。长度为负”;反序列化avro类时

Java &引用;格式错误的数据。长度为负”;反序列化avro类时,java,spring,apache-kafka,avro,spring-cloud-stream,Java,Spring,Apache Kafka,Avro,Spring Cloud Stream,我将卡夫卡与avro序列化一起使用: 我在本地架构注册表中注册了架构,并使用application.yml中的设置将ed@EnableSchemaRegistryClient添加到我的应用程序中: spring: cloud: stream: bindings: output: destination: output input: destination: topicName c

我将卡夫卡与avro序列化一起使用:

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

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
生成了这个类。现在,我正试图阅读并转换来自卡夫卡的信息:

  @StreamListener(Sink.INPUT)
  public void handlePublish(MyClass message) throws IOException {
    logger.info("Receiving MyClass" + message);
  }
但是转换器失败,原因是:
org.apache.avro.AvroRuntimeException:数据格式错误。长度为负

堆栈跟踪:

 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

此链接可能会有所帮助。