# Kafkacat ("netcat for Kafka")

**URL:** <https://forum.confluent.io/t/kafkacat-netcat-for-kafka/44>\
**Category:** Command Line tools\
**Created:** [5 November 2020 22:24 UTC](https://forum.confluent.io/t/kafkacat-netcat-for-kafka/44 "2020-11-05T22:24:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmoff](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/rmoff/32/3_2.png) [@rmoff](https://forum.confluent.io/u/rmoff)\
**Post date:** [5 November 2020 22:24 UTC](https://forum.confluent.io/t/kafkacat-netcat-for-kafka/44/1 "2020-11-05T22:24:49Z")

</div>

## What is kafkacat?

**kafkacat** is a generic non-JVM producer and consumer for Apache Kafka \>=0.8, think of it as a **netcat for Kafka**.

Download: [GitHub - edenhill/kcat: Generic command line non-JVM Apache Kafka producer and consumer](https://github.com/edenhill/kafkacat/)

## kafkacat examples

- In **producer** mode kafkacat reads messages from stdin, delimited with a configurable delimiter (-D, defaults to newline), and produces them to the provided Kafka cluster (-b), topic (-t) and optionally, partition (-p).

- In **consumer** mode kafkacat reads messages from a topic and partition and prints them to stdout using the configured message delimiter.

- kafkacat also features a Metadata list (-L) mode to display the current state of the Kafka cluster and its topics and partitions.

## Using kafkacat with Confluent Cloud

Here’s an example with kafkacat, taking advantage of running it directly from Docker too:

```auto
$ docker run --rm --interactive edenhill/kafkacat:1.6.0 \
            -X security.protocol=SASL_SSL -X sasl.mechanisms=PLAIN \
            -X ssl.ca.location=./etc/ssl/cert.pem -X api.version.request=true \
            -b $CCLOUD_BROKER_HOST \
            -X sasl.username="$CCLOUD_API_KEY" \
            -X sasl.password="$CCLOUD_API_SECRET" \
            -t rmoff_test_topic_01 -C -u -e
Hello world!
This is a message on a topic in Confluent Cloud

```

You can also output the message in JSON which can be useful:

```auto
$ docker run --rm --interactive edenhill/kafkacat:1.6.0 \
            -X security.protocol=SASL_SSL -X sasl.mechanisms=PLAIN \
            -X ssl.ca.location=./etc/ssl/cert.pem -X api.version.request=true \
            -b $CCLOUD_BROKER_HOST \
            -X sasl.username="$CCLOUD_API_KEY" \
            -X sasl.password="$CCLOUD_API_SECRET" \
            -t rmoff_test_topic_01 -C -u -J -e

```

```javascript
{
  "topic": "rmoff_test_topic_01",
  "partition": 0,
  "offset": 0,
  "tstype": "create",
  "ts": 1604571163960,
  "broker": 7,
  "key": null,
  "payload": "Hello world!"
}
{
  "topic": "rmoff_test_topic_01",
  "partition": 3,
  "offset": 0,
  "tstype": "create",
  "ts": 1604571168723,
  "broker": 1,
  "key": null,
  "payload": "This is a message on a topic in Confluent Cloud"
}

```

## Articles

- [🔗 Setting key value when piping to `kafkacat`](https://rmoff.net/2020/09/30/setting-key-value-when-piping-from-jq-to-kafkacat/)
- [🔗 Viewing Kafka messages bytes as hex with `kafkacat`](https://rmoff.net/2020/07/03/why-json-isnt-the-same-as-json-schema-in-kafka-connect-converters-viewing-kafka-messages-bytes-as-hex/)
- [🔗 How to install kafkacat on Fedora](https://rmoff.net/2020/04/20/how-to-install-kafkacat-on-fedora/)
- [🔗 Sending multiline messages to Kafka](https://rmoff.net/2018/09/04/sending-multiline-messages-to-kafka/)

---

<div class="post-metadata">

**Author:** ![rmoff](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/rmoff/32/3_2.png) [@rmoff](https://forum.confluent.io/u/rmoff)\
**Post date:** [5 November 2020 22:25 UTC](https://forum.confluent.io/t/kafkacat-netcat-for-kafka/44/2 "2020-11-05T22:25:26Z")

</div>



---

<div class="post-metadata">

**Author:** ![rmoff](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/rmoff/32/3_2.png) [@rmoff](https://forum.confluent.io/u/rmoff)\
**Post date:** [5 November 2020 22:25 UTC](https://forum.confluent.io/t/kafkacat-netcat-for-kafka/44/3 "2020-11-05T22:25:36Z")

</div>


