A hands-on demo for quickly starting Kafka. You will:
- Download Confluent Platform
- Start a local development deployment
- Create a topic
- Write to the topic using Confluent Control Center and command-line tools
- Read from the topic using Confluent Control Center and command-line tools
So let’s have a quick look at Kafka, how you can install it and use it
So first of all how would you download Kafka? In this presentation we will use a Confluent platform
so if you want to download Confluent platform
you just go to the Confluent website, here’s a site that allows you to download a zip archive
of confIuent platform, you just use this command and download it, for the sake of the time I have
downloaded it beforehand and already extracted it. To start a Confluent platform you just use the
Confluent local services start command. After this comment runs and I have already run it beforehand
You can visit localhost at port 9021 and here’s a Confluent control center
website, where you can control and manage your cluster, as you can see there’s only one cluster
visible here, that’s the cluster I started. If you click it you have one
broker because I started it locally on my computer, you can go to topics
and create topics, so in this case, we’ll create a new topic we call it that’s topic one
and now it’s created
as you can see below the offset
value determines how many messages are in this topic and currently, there are none
so you can use the web-based UI to send messages to this topic
so let’s send one message to this topic, we’ll send a JSON message
as you can see it consists of a key and a value so in a key, you could have something like ID
and in a value, you could have something like the actual content of the message
after sending the message you can see it was correctly sent
and it consists of the value
and the key
So that’s the way you could see the messages in a Confluent web-based UI
If you jump to offset zero so the first message that was sent, you can get it back
Of course, it might be useful to send the messages using the console
tools that Kafka offers, so for example if you want to test something in your development
deployment, to send messages using the console consumer
will use the Kafka console consumer binary
When starting this comment you have to specify the bootstrap server
so the server to connect to, in this case, we’ll connect to localhost
Next, you have to specify the topic you want to read from in this case we’ll consume
from this topic and by default, console consumer reads only from the time it was
started, so it will not see a message we just sent but you can specify, a from beginning flag
You can see the message that we sent is here, but only a value of this message is visible so
also print the key you have to specify the print key property
and as you can see there’s the key
and there’s the value, similarly, you can use the console tools to produce messages to Kafka
You will use the console producer command
So if we go back to the web-based UI and go to offset one, so the second message
we will see that this message was correctly sent
So the last thing that will be useful for you is stopping Confluent
As you can remember we use the Confluent local services start, to start Confluent
If you invoke stop
The entire Confluent platform is stopped so the web-based UI is now not visible and the
Kafka server is now stopping and if you want to destroy all the data in this local deployment
you just say, local destroy and all the data is removed
So that was a quick demo of Kafka we downloaded the Confluent and platform
Of course, I had it downloaded beforehand to make it quicker, we started the deployment
we created the topic, we wrote to this topic using Confluent Control Center and
command-line tools and we read it back using both control center and command-line tools