【发布时间】: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]
....
【问题讨论】:
-
stackoverflow.com/questions/36022358/… 这个链接可能会有所帮助。
标签: java spring apache-kafka avro spring-cloud-stream