Kafka

Start Consumer to receive messages

Start Consumer to receive messages

Here is the syntax for messages to show in the consumer terminal- 

 

bin/kafka-console-consumer.sh --zookeeper localhost:4536 —topic topic-name 

--from-beginning

 

The default consumer properties will be applicable unless specified otherwise in the ‘config/consumer.proper-ties’ file. 

 

Creating a topic using multiple Kafka configuration 

 

The syntax for this will be -

 

bin/kafka-topics.sh --create --zookeeper localhost:4381 --replication-factor 

-partitions 1 --topic topic-name

 

Here, the replication factor is chosen according to the number of brokers running. Let us see an example of the resultant syntax with a replication factor of 2 -

 

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 

-partitions 1 --topic Multibrokerapplication

 

The output will be -

 

created topic “Multibrokerapplication”

 

You can also use the ‘Describe’ command to verify which broker is listening to a particular topic. 

bin/kafka-topics.sh --describe --zookeeper localhost:2671 

--topic Multibrokerappli-cation  

 

The output will be displayed as -

 

bin/kafka-topics.sh --describe --zookeeper localhost:2671 

--topic Multibrokerappli-cation

 

Topic:Multibrokerapplication    PartitionCount:1 

ReplicationFactor:2 Configs:

   

Topic:Multibrokerapplication Partition:0 Leader:0 

Replicas:0,2,1 Isr:0,2,1

 

This first line of this output summarizes the number of partitions including topic name, partition count and replication factor. The second line indicates that the leader is the first broker with broker id 0 and all brokers replicate the subset of the topic ‘lsr.’