<ahref="https://www.apache.org/dyn/closer.cgi?path=/kafka/0.9.0.0/kafka_2.10-0.9.0.0.tgz"title="Kafka downloads">Download</a> the 0.9.0.0 release and un-tar it.
Kafka uses ZooKeeper so you need to first start a ZooKeeper server if you don't already have one. You can use the convenience script packaged with kafka to get a quick-and-dirty single-node ZooKeeper instance.
Alternatively, instead of manually creating topics you can also configure your brokers to auto-create topics when a non-existent topic is published to.
<h4>Step 4: Send some messages</h4>
Kafka comes with a command line client that will take input from a file or from standard input and send it out as messages to the Kafka cluster. By default each line will be sent as a separate message.
<p>
Run the producer and then type a few messages into the console to send to the server.
Kafka also has a command line consumer that will dump out messages to standard output.
<pre>
><b>bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning</b>
This is a message
This is another message
</pre>
<p>
If you have each of the above commands running in a different terminal then you should now be able to type messages into the producer terminal and see them appear in the consumer terminal.
</p>
<p>
All of the command line tools have additional options; running the command with no arguments will display usage information documenting them in more detail.
</p>
<h4>Step 6: Setting up a multi-broker cluster</h4>
So far we have been running against a single broker, but that's no fun. For Kafka, a single broker is just a cluster of size one, so nothing much changes other than starting a few more broker instances. But just to get feel for it, let's expand our cluster to three nodes (still all on our local machine).
<p>
First we make a config file for each of the brokers:
Now edit these new files and set the following properties:
<pre>
config/server-1.properties:
broker.id=1
port=9093
log.dir=/tmp/kafka-logs-1
config/server-2.properties:
broker.id=2
port=9094
log.dir=/tmp/kafka-logs-2
</pre>
The <code>broker.id</code> property is the unique and permanent name of each node in the cluster. We have to override the port and log directory only because we are running these all on the same machine and we want to keep the brokers from all trying to register on the same port or overwrite each others data.
<p>
We already have Zookeeper and our single node started, so we just need to start the two new nodes:
Here is an explanation of output. The first line gives a summary of all the partitions, each additional line gives information about one partition. Since we have only one partition for this topic there is only one line.
<ul>
<li>"leader" is the node responsible for all reads and writes for the given partition. Each node will be the leader for a randomly selected portion of the partitions.
<li>"replicas" is the list of nodes that replicate the log for this partition regardless of whether they are the leader or even if they are currently alive.
<li>"isr" is the set of "in-sync" replicas. This is the subset of the replicas list that is currently alive and caught-up to the leader.
</ul>
Note that in my example node 1 is the leader for the only partition of the topic.
<p>
We can run the same command on the original topic we created to see where it is: