{"id":5594,"date":"2025-06-12T22:59:25","date_gmt":"2025-06-12T22:59:25","guid":{"rendered":"https:\/\/dalelane.co.uk\/blog\/?p=5594"},"modified":"2026-03-14T21:24:52","modified_gmt":"2026-03-14T21:24:52","slug":"how-to-use-kafka-console-consumer-sh-to-view-the-contents-of-apache-avro-encoded-events","status":"publish","type":"post","link":"https:\/\/dalelane.co.uk\/blog\/?p=5594","title":{"rendered":"How to use kafka-console-consumer.sh to view the contents of Apache Avro-encoded events"},"content":{"rendered":"<p><code style=\"color: #770000;background-color: #FFFFC0;padding: 0.2em 0.4em;font-size: 1.1em;font-weight: bold;\">kafka-console-consumer.sh<\/code> is one of the most useful tools in the Kafka user&#8217;s toolkit. But if your topic has Avro-encoded events, the output can be a bit hard to read. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images.dalelane.co.uk\/2025-06-12-avro\/raw.png?raw=true\" style=\"width: 100%; max-width: 675px;\"\/><\/p>\n<p>You don\u2019t have to put up with that, as the tool has a <a href=\"https:\/\/kafka.apache.org\/39\/javadoc\/org\/apache\/kafka\/common\/MessageFormatter.html\">formatter plugin framework<\/a>. With the right plugin, you can get nicely formatted output from your Avro-encoded events. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images.dalelane.co.uk\/2025-06-12-avro\/formatted.png?raw=true\" style=\"width: 100%; max-width: 675px;\"\/><\/p>\n<p>With this in mind, I\u2019ve written a new Avro formatter for a few common Avro situations. You can find it at:<\/p>\n<p><strong><a style=\"font-size: 1.1em;\" href=\"https:\/\/github.com\/IBM\/kafka-avro-formatters\">github.com\/IBM\/kafka-avro-formatters<\/a><\/strong><\/p>\n<p>The <a href=\"https:\/\/github.com\/IBM\/kafka-avro-formatters\/blob\/main\/README.md\">README<\/a> includes instructions on how to add it to your Kafka console command, and configure it with how to find your schema. <\/p>\n<p><!--more-->I won&#8217;t duplicate those instructions here, but I do want to briefly call out a few ways you can use it, depending on where your Avro schema is.<\/p>\n<hr \/>\n<h3>Schemas in Apicurio Schema Registry<\/h3>\n<p>If you keep your schema in an <a href=\"https:\/\/www.apicur.io\/registry\/\">Apicurio schema registry<\/a> the formatter can dynamically fetch the schemas it needs from the registry (just like your regular deserializer would).<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images.dalelane.co.uk\/2025-06-12-avro\/apicurio.png?raw=true\" style=\"width: 100%; max-width: 675px;\"\/><\/p>\n<hr \/>\n<h3>Schemas in local files<\/h3>\n<p>If you keep your schema together with your application source code, and have it available in a local file, then the formatter can just read that local file directly.  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images.dalelane.co.uk\/2025-06-12-avro\/file.png?raw=true\" style=\"width: 100%; max-width: 675px;\"\/><\/p>\n<hr \/>\n<h3>Schemas in Event Endpoint Management<\/h3>\n<p>If you\u2019re consuming events from someone else\u2019s topic that you found in <a href=\"https:\/\/www.ibm.com\/products\/event-automation\/event-endpoint-management\">Event Endpoint Management<\/a>, then the formatter can fetch any schemas it needs from the Catalog.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images.dalelane.co.uk\/2025-06-12-avro\/eem.png?raw=true\" style=\"width: 100%; max-width: 675px;\"\/><\/p>\n<hr \/>\n<p>I hope you\u2019ll find this useful. If you have any ideas for what else it could do, please feel free to <a href=\"https:\/\/github.com\/IBM\/kafka-avro-formatters\/issues\">create an issue in the Github repository<\/a>.<\/p>\n<h3>Extra tips<\/h3>\n<p>Finally, I want to highlight a couple of <a href=\"https:\/\/github.com\/IBM\/kafka-avro-formatters\/blob\/main\/README.md#tips\">quick tips for how to get more<\/a> out of the formatter:<\/p>\n<h4>Use a properties file and a shell alias<\/h4>\n<p>Save yourself some typing! <\/p>\n<p>Instead of typing your schema registry URL and credentials in <code style=\"color: #770000;background-color: #FFFFC0;padding: 0.2em 0.4em;font-size: 1.1em;font-weight: bold;\">--property<\/code> options every time you use kafka-console-consumer.sh, leave them all in a properties file and create an Avro-themed alias for kafka-console-consumer that points at your properties file. <\/p>\n<p>(See an <a href=\"https:\/\/github.com\/IBM\/kafka-avro-formatters\/blob\/main\/README.md#use-an-alias\">example of how to do this<\/a>)<\/p>\n<h4>Pair it with jq<\/h4>\n<p>The formatter outputs the parsed Avro-encoded events as a JSON string. This means that you can pipe it to something like <a href=\"https:\/\/jqlang.org\/\">jq<\/a> for colour formatting and advanced parsing and processing. <\/p>\n<p>This is very useful with large and complex event data, where you just want to view specific fields. <\/p>\n<p>(See an <a href=\"https:\/\/github.com\/IBM\/kafka-avro-formatters\/blob\/main\/README.md#combine-with-jq\">example of how to do this<\/a>)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>kafka-console-consumer.sh is one of the most useful tools in the Kafka user&#8217;s toolkit. But if your topic has Avro-encoded events, the output can be a bit hard to read. You don\u2019t have to put up with that, as the tool has a formatter plugin framework. With the right plugin, you can get nicely formatted output [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5600,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[595,593,594,583,584],"class_list":["post-5594","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code","tag-apacheavro","tag-apachekafka","tag-avro","tag-ibmeventstreams","tag-kafka"],"_links":{"self":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5594","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5594"}],"version-history":[{"count":1,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5594\/revisions"}],"predecessor-version":[{"id":5897,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5594\/revisions\/5897"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/media\/5600"}],"wp:attachment":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}