SerializationException:反序列化 Avro 消息时出错(StringIndexOutOfBoundsException)

SerializationException: Error deserializing Avro message (StringIndexOutOfBoundsException)

当 KafkaStream 尝试反序列化 Arvo 消息时,我 运行 遇到了这个错误:

[filtering-app-6adef284-11eb-48f8-8ca0-cde7da5224ab-StreamThread-1] ERROR org.apache.kafka.streams.KafkaStreams - stream-client [filtering-app-6adef284-11eb-48f8-8ca0-cde7da5224ab] All stream threads have died. The instance will be in error state and should be closed.
[filtering-app-6adef284-11eb-48f8-8ca0-cde7da5224ab-StreamThread-1] INFO org.apache.kafka.streams.processor.internals.StreamThread - stream-thread [filtering-app-6adef284-11eb-48f8-8ca0-cde7da5224ab-StreamThread-1] Shutdown complete
Exception in thread "filtering-app-6adef284-11eb-48f8-8ca0-cde7da5224ab-StreamThread-1" org.apache.kafka.streams.errors.StreamsException: Deserialization exception handler is set to fail upon a deserialization error. If you would rather have the streaming pipeline continue after a deserialization error, please set the default.deserialization.exception.handler appropriately.
    at org.apache.kafka.streams.processor.internals.RecordDeserializer.deserialize(RecordDeserializer.java:80)
    at org.apache.kafka.streams.processor.internals.RecordQueue.maybeUpdateTimestamp(RecordQueue.java:160)

原因异常是:

Caused by: org.apache.kafka.common.errors.SerializationException: Error deserializing Avro message for id 1
Caused by: java.lang.RuntimeException: java.lang.StringIndexOutOfBoundsException: begin 1, end 0, length 1
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1529)

Caused by: java.lang.StringIndexOutOfBoundsException: begin 1, end 0, length 1
    at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319)
    at java.base/java.lang.String.substring(String.java:1874)

avro 配置很简单:

{
  "namespace": "io.confluent.developer.avro",
  "type": "record",
  "name": "Publication",
  "fields": [
    {"name": "name", "type": "string"},
    {"name": "title", "type": "string"}
  ]
}

来自本教程:https://kafka-tutorials.confluent.io/filter-a-stream-of-events/kstreams.html。生产者序列化输入字符串 "{"name": "George R. R. Martin", "title": "A Dream of Spring"}" 没有问题,但是基本上尝试过滤事件的 KafkaStream 失败了反序列化对象以执行 Java 过滤逻辑...

有没有人遇到过这个问题?感谢任何建议!

发现问题:代理挡路。

根本原因是应用程序无法连接到架构注册表。在这里记一下,以防以后有人遇到同样的问题。