Note: The following steps require the use of commands in a terminal. These commands will work in macOS and Linux. Windows users can use Windows Subsystem for Linux (WSL) to obtain a Linux-compatible environment on their system.
You’ll be using kcat, a command-line tool, to connect to your Kafka instance. The kcat command-line interface (CLI) allows you to produce or consume messages, and list metadata for the Kafka cluster without having to write custom code. Download and install kcat using the appropriate option for your system, following the kcat installation guide.
To connect to your Kafka instance using kcat, you will need a client ID, client secret, and bootstrap server URL. Along with the credentials (client ID and secret), you will need the URL for the Kafka instance you want to connect to—that is the bootstrap server URL. You already recorded the client ID and secret when you created the service account. You can obtain the bootstrap server URL as follows:
- Navigate to the Kafka Instances page.
- Click on the Options icon (three dots) on the right-hand side of your listed Kafka instance, and select Connection.
- Copy the Bootstrap Server URL field (Figure 13).
- Store the bootstrap URL in the same location as your client ID and client secret.
- Run the following kcat command to list metadata for your Kafka instance. Replace the variables with the correct values. For instance, $BOOTSTRAP_URL should be replaced with the bootstrap server URL you copied from the dashboard:
$ kcat -b $BOOTSTRAP_SERVER -X security.protocol=SASL_SSL -X sasl.mechanisms=PLAIN -X sasl.username="$CLIENT_ID" -X sasl.password="$CLIENT_SECRET" -L
If you see text output similar to the following sample, you’ve successfully completed this learning path:
Metadata for all topics (from broker -1: sasl_ssl://os-kafka-c-upkp-mg-ippe-o-vba.bf2.kafka.rhcloud.com:443/bootstrap): 3 brokers: broker 0 at broker-0-os-kafka-c-upkp-mg-ippe-o-vba.bf2.kafka.rhcloud.com:443 broker 2 at broker-2-os-kafka-c-upkp-mg-ippe-o-vba.bf2.kafka.rhcloud.com:443 broker 1 at broker-1-os-kafka-c-upkp-mg-ippe-o-vba.bf2.kafka.rhcloud.com:443 (controller) 0 topics: