Step 1: Download KafkaClick to download the latest version and unzip it.
Tar-xzf kafka_2.9.2-0.8.1.1.tgz CD kafka_2.9.2-0.8.1.1
Step 2: Start the service Kafka used to zookeeper, all start Zookper First, the following simple to enable a single-instance Zookkeeper service. You can add a & symbol at the end of the command so that you can start and leave the console.
bin/zookeeper-server-start.sh. /config/zookeeper.properties &[2013-04-22 15:01:37,495] INFO Reading configuration from:config/ Zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig) ...
Start Kafka Now:
bin/kafka-server-start.sh. /config/server.properties[2013-04-22 15:01:47,028] INFO Verifying properties (kafka.utils.VerifiableProperties ) [2013-04-22 15:01:47,051] INFO property socket.send.buffer.bytes was overridden to 1048576 ( Kafka.utils.VerifiableProperties) ...
Step 3: Create topic Create a topic called "Test", which has only one partition and one copy.
bin/kafka-topics.sh--create--zookeeper localhost:2181--replication-factor 1--partitions 1--topic test
You can view the created topic by using the List command:
bin/kafka-topics.sh--list--zookeeper localhost:2181test
In addition to manually creating topic, you can also configure the broker to have it automatically create topic. Step 4: Send a message. Kafka uses a simple command-line producer to read the message from the file or from the standard input and send it to the server. A message is sent by default for each command.
Run producer and lose some messages in the console that will be sent to the server:
bin/kafka-console-producer.sh--broker-list localhost:9092--topic Test this was a messagethis is another message
CTRL + C can exit send.
Step 5: Start Consumerkafka also have a command line consumer, that would dump out messages to standard output. Kafka also has a command line consumer can read messages and output to standard output:
bin/kafka-console-consumer.sh--zookeeper localhost:2181--topic test--from-beginning This was a messagethis is another message
You run the consumer command line in one terminal, the other terminal runs the producer command line, you can enter the message at one terminal, and the other terminal reads the message.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Linux Kafka build a running environment