To understand and use initial level Apache kafka we need to install it on our machine. As i am using window i had downloaded kafka_2.13-2.6.0.tgz the same from the belwo site.
https://kafka.apache.org/downloads
extract it and set the required environment variable so that you can directly use it when you open any cmd prompt.
i.e.
KAFKA_HOME C:\kafka_2.13-2.6.0\bin
However you can also take he commercial version from confluent.io or also used the managed service from cloud system like confluent, amazone etc.
benefit of using commercial version is that they provided a bunch of tool and support that is needed to you. most likely in prod env we are going to use the confluent.io.Additional for managed approach from cloude we dont need to think of anything all infra needs are taken care by them we only get the instance and we are good to go with it.
Now there is sequence of step that we need to for starting our Apache cluster in local machine.
Step 1 :-
‘- Zookeper starting
Zookeper is bundled by default with Apache kafka it is used to monitor kafka. To understand it visit this site.
https://zookeeper.apache.org/index.html. Zookeeper keeps track of status of the Kafka cluster nodes and it also keeps track of Kafka topics, partitions etc. Zookeeper it self is allowing multiple clients to perform simultaneous reads and writes and acts as a shared configuration service within the system.
C:\kafka_2.13-2.6.0\bin\windows>zookeeper-server-start.bat ../../config/zookeeper.properties
Step 2:-
‘- kafka broker
Then we will start the broker using below command.
C:\kafka_2.13-2.6.0\bin\windows>kafka-server-start.bat C:\kafka_2.13-2.6.0\config\server.properties
Note:- We can create many broker as we want only the changes we want to in the C:\kafka_2.13-2.6.0\config\server.properties are
1- broker.id=0
2- log.dirs=/tmp/kafka-logs
3- listeners=PLAINTEXT://:9092
Step 3:-
‘- Create Topics
We will create a topic where we are going to store our message send from the producer.
C:\kafka_2.13-2.6.0\bin\windows>kafka-topics.bat –create –zookeeper localhost:2181 –replication-factor 1 –partitions 1 –topic test-siddhu
Ste 4:-
‘- consumer
We will create a consumer who will send a message to above created topics.
C:\kafka_2.13-2.6.0\bin\windows>kafka-console-consumer.bat –bootstrap-server localhost:9092 –topic test-siddhu –from-beginning
Step 5:-
‘- producer
We will create a producer which will read the data entered in to the Topic by Producer.
C:\kafka_2.13-2.6.0\bin\windows>kafka-console-producer.bat –broker-list localhost:9092 –topic test-siddhu
Step 6:-
‘- Check topic is created and list of the topics.
C:\kafka_2.13-2.6.0\bin\windows>kafka-topics.bat –list –zookeeper localhost:2181
test-siddhu
‘- Topic descriptions
C:\kafka_2.13-2.6.0\bin\windows>kafka-topics.bat –describe -zookeeper localhost:2181 –topic test-siddhu
Topic: test-siddhu PartitionCount: 1 ReplicationFactor: 1 Configs:
Topic: test-siddhu Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Now lets send the data from the producer and check it is coming to consumer. We had created/setup the apache kafka with one producer and one consumer
No comments:
Post a Comment