Kafkacat
Message-Hub
Data Streaming
Event Driven
Technology Tutorial

How to use kafkacat with message-hub

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

kafkacat, now commonly referred to as kcat, is a command-line Kafka client that can produce messages, consume messages, and inspect broker metadata. When using it with a managed Kafka service such as IBM Message Hub style deployments, the important part is not the basic Kafka command syntax but the SASL and SSL configuration required by the provider.

What You Need

To connect successfully, you typically need:

  • broker addresses
  • a topic name
  • SASL mechanism details
  • username and password or token
  • a CA trust location if TLS validation is required

The exact credential names vary by provider, but the flow is the same: take the broker list and security settings from the service credentials and pass them to kafkacat.

Produce a Message

bash
1echo "hello" | kafkacat \
2  -b broker1:9093,broker2:9093 \
3  -t my-topic \
4  -P \
5  -X security.protocol=SASL_SSL \
6  -X sasl.mechanisms=PLAIN \
7  -X sasl.username=token \
8  -X sasl.password='YOUR_PASSWORD'

This sends one message to my-topic. The important options are the -X properties, which configure security.

Consume Messages

bash
1kafkacat \
2  -b broker1:9093,broker2:9093 \
3  -t my-topic \
4  -C \
5  -o beginning \
6  -X security.protocol=SASL_SSL \
7  -X sasl.mechanisms=PLAIN \
8  -X sasl.username=token \
9  -X sasl.password='YOUR_PASSWORD'

-C means consume mode, and -o beginning tells the client to start from the beginning of the topic rather than only new messages.

Put the Security Settings in a Config File

Typing every property repeatedly is error-prone, so it is often easier to keep them in a config file:

text
1security.protocol=SASL_SSL
2sasl.mechanisms=PLAIN
3sasl.username=token
4sasl.password=YOUR_PASSWORD
5ssl.ca.location=/etc/ssl/certs

Then call:

bash
kafkacat -F kafkacat.conf -b broker1:9093,broker2:9093 -L

-L asks for metadata, which is one of the safest first tests because it verifies that the connection and authentication work before you start debugging producer or consumer logic.

Why Metadata Checks Matter

If metadata lookup fails, the problem is usually connectivity, TLS trust, or SASL credentials. If metadata works but producing fails, the issue is more likely topic naming, ACLs, or partition-level permissions.

That staged debugging approach saves time because it separates transport problems from topic-authorization problems.

Streaming and Inspection

Once the connection works, kafkacat becomes a convenient debugging tool. You can:

  • inspect cluster metadata
  • read a topic from the beginning
  • pipe JSON messages from shell commands into Kafka
  • verify that a managed Kafka service is reachable from your machine

That is why it remains useful even in environments with full application clients available.

It is particularly helpful for separating platform issues from application issues. If kafkacat cannot authenticate, the application is unlikely to authenticate either, and you can keep the early debugging focused on credentials and network reachability instead of client-library code.

That keeps the troubleshooting loop much shorter.

Common Pitfalls

  • Forgetting SASL_SSL and trying plain Kafka defaults against a managed service.
  • Putting the wrong username token format into the SASL settings.
  • Debugging produce or consume before first verifying metadata access.
  • Forgetting CA trust configuration when TLS certificate validation is required.
  • Mixing provider-specific credential labels with generic Kafka property names.

Summary

  • 'kafkacat connects to managed Kafka by combining broker addresses with the correct SASL and TLS settings.'
  • Start with metadata lookup before testing produce or consume commands.
  • Store repeated security properties in a config file.
  • Most failures come from auth or TLS configuration, not from Kafka syntax itself.
  • Once configured, kafkacat is an excellent command-line tool for managed Kafka debugging.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.