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.
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
This sends one message to my-topic. The important options are the -X properties, which configure security.
Consume Messages
-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:
Then call:
-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_SSLand 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
- '
kafkacatconnects 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,
kafkacatis an excellent command-line tool for managed Kafka debugging.
Related reading
- How to use kafka.group.id and checkpoints in spark 3.0 structured streaming to continue to read from Kafka where it left off after restart?
- How to use multi-thread consumer in kafka 0.9.0?
- How to use priority in celery task.apply_async
- How to use Rabbit inside a gitlab-ci.yml file?
- How to use rabbitmqctl to connect to the rabbitmqserver in the docker container?
- How to use Spark Structured Streaming with Kafka Direct Stream?
- How to use the Kafka Connect JDBC to source PostgreSQL with multiple schemas that contain tables with the same name?
- How to use the rabbitmq docker compose yml file to build docker image?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack 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.