Search code examples
apache-kafkaconfluent-platformconfluent-schema-registry

How can I print the schema id from kafka-console-consumer?


I want to print the schema id of a received avro message from kafka-console-consumer.

I have tried the following command from inside confluent platform (docker-based):

kafka-console-consumer --bootstrap-server localhost:9092 --topic topic_name \
--property print.schema.ids=true --property \
 schema.registry.url="http://schema-registry:8081" \
--value-deserializer io.confluent.kafka.serializers.KafkaAvroDeserializer

But I get the following exception:

Exception in thread "main" org.apache.kafka.common.config.ConfigException: Missing required configuration "schema.registry.url" which has no default value.
        at org.apache.kafka.common.config.ConfigDef.parseValue(ConfigDef.java:515)
        at org.apache.kafka.common.config.ConfigDef.parse(ConfigDef.java:505)
        at org.apache.kafka.common.config.AbstractConfig.<init>(AbstractConfig.java:112)
        at org.apache.kafka.common.config.AbstractConfig.<init>(AbstractConfig.java:132)
        at io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig.<init>(AbstractKafkaSchemaSerDeConfig.java:295)
        at io.confluent.kafka.serializers.KafkaAvroDeserializerConfig.<init>(KafkaAvroDeserializerConfig.java:58)
        at io.confluent.kafka.serializers.KafkaAvroDeserializer.configure(KafkaAvroDeserializer.java:48)
        at kafka.tools.DefaultMessageFormatter.getDeserializerProperty(ConsoleConsumer.scala:609)
        at kafka.tools.DefaultMessageFormatter.$anonfun$configure$22(ConsoleConsumer.scala:515)
        at kafka.tools.DefaultMessageFormatter.configure(ConsoleConsumer.scala:615)
        at kafka.tools.ConsoleConsumer$ConsumerConfig.<init>(ConsoleConsumer.scala:325)
        at kafka.tools.ConsoleConsumer$.main(ConsoleConsumer.scala:51)
        at kafka.tools.ConsoleConsumer.main(ConsoleConsumer.scala)

What am I missing. Is there any other flag that I should instead use?


Solution

  • i tried to do the same as you today and came upon:

    kafka-avro-console-consumer \
      --topic topic_name  \
      --property schema.registry.url=http://localhost:8081 \
      --bootstrap-server kafka-broker:9092 \
      --property print.key=true \
      --property print.schema.ids=true \
      --property key.separator="-" \
      --partition 0 \
      --offset 2423843 \
      --max-messages 3
    

    this CLI command exists in the confluentinc/cp-schema-registry docker image.

    Here some related information: