How can I consume messages from Confluent Community on the command line?

Hi, I am using Confluent Cloud and want to read messages from a topic using the command line - how can I do that?

With your data in Confluent Cloud you can use tools like ccloud or kafkacat to access your data from the commandline.

Confluent Cloud CLI ( ccloud )

$ ccloud kafka topic consume --from-beginning rmoff_test_topic_01
Starting Kafka Consumer. ^C or ^D to exit
Hello world!
This is a message on a topic in Confluent Cloud

kafkacat

You can run kafkacat locally, or use it from Docker.

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:

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
{
  "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"
}
1 Like