edenhill / kcat

Generic command line non-JVM Apache Kafka producer and consumer
Other
5.46k stars 484 forks source link

Avro Deserialization error when using nested schema #277

Open tcozien opened 4 years ago

tcozien commented 4 years ago

I'm currently using the kafka-avro-console-consumer from the schema registry to consume avro messages. Unfortunately, I'm not able to read the same messages with Kafkacat.

Context

We have basically two schemas mynamespace.Schema1 and mynamespace.Nested, one depending on the other:

{
  "namespace": "mynamespace",
  "type": "record",
  "name": "Schema1",
  "fields": [
    {
      "name": "id",
      "type": "string"
    },
    {
      "name": "nested",
      "type": [
        "mynamespace.Nested"
      ]
    }
  ]
}
{
  "namespace": "mynamespace",
  "type": "record",
  "name": "Nested",
  "fields": [
    {
      "name": "nestedId",
      "type": "string"
    }
  ]
}

Those schemas are added to the Schema Registry with the REST API, starting with the last one as it's a dependency of the first one.

Error

Using the following command to troubleshoot:

kafkacat -b $BOOTSTRAP_BROKERS -F client.config -t mytopic -c1 -s value=avro -r $SCHEMA_REGISTRY -v -X schema.registry.debug=all

The output displayed:

% Reading configuration from file app/client.config
% Auto-selecting Consumer mode (use -P or -C to override)
%7|1603339938.748|INIT|rdkafka#consumer-1| [thrd:app]: librdkafka v1.5.0 (0x10500ff) rdkafka#consumer-1 initialized (builtin.features gzip,snappy,ssl,sasl,regex,lz4,sasl_gssapi,sasl_plain,sasl_scram,plugins,zstd,sasl_oauthbearer, GCC GXX PKGCONFIG GNULD C11THREADS LIBDL PLUGINS ZLIB SSL SASL_CYRUS ZSTD HDRHISTOGRAM SYSLOG SNAPPY SOCKEM SASL_SCRAM SASL_OAUTHBEARER CRC32C_HW, debug 0x2000)
%7|1603339939.005|PROTOERR|rdkafka#consumer-1| [thrd:ssl://broker_url]: ssl://broker_urlon.com:9094/bootstrap: Protocol parse failure for ApiVersion v3 at 3/6 (rd_kafka_handle_ApiVersion:1945) (incorrect broker.version.fallback?)
%7|1603339939.005|PROTOERR|rdkafka#consumer-1| [thrd:ssl://broker_url]: ssl://broker_urlon.com:9094/bootstrap: ApiArrayCnt -1 out of range
%7|1603339939.202|PROTOERR|rdkafka#consumer-1| [thrd:ssl://broker_url]: ssl://broker_urlon.com:9094/1: Protocol parse failure for ApiVersion v3 at 3/6 (rd_kafka_handle_ApiVersion:1945) (incorrect broker.version.fallback?)
%7|1603339939.202|PROTOERR|rdkafka#consumer-1| [thrd:ssl://broker_url]: ssl://broker_urlon.com:9094/1: ApiArrayCnt -1 out of range
%7|1603339939.324|FETCH|rdkafka#consumer-1| [thrd:main]: Partition mytopic [0] start fetching at offset 5176300
% SERDES-7-SCHEMA_LOAD: Received schema (null) (68) definition: {"namespace":"mynamespace","type":"record","name":"Schema1","fields":[{"name":"id","type":"string"},{"name":"nested","type":["mynamespace.Nested"]}]}
% SERDES-7-SCHEMA_LOAD: Schema load of (null) failed: Unknown Avro "type": Nested
% Error at fmt_msg_output_str:565:
% ERROR: Failed to format message in mytopic [0] at offset 5176300: Avro/Schema-registry message deserialization: Unknown Avro "type": Nested : terminating

First of all, I notice a few PROTOERR lines and wondering if the communication with the cluster is good. Then, looking at the error message, it looks like kafkacat is able to decode the first part of the message but doesn't manage to get the nested schema, maybe because of the namespace 🤷‍♂️

royyeah commented 2 years ago

Also running into issues with nested Avro schema's - any update on this?