{"id":5400,"date":"2024-12-17T15:09:56","date_gmt":"2024-12-17T15:09:56","guid":{"rendered":"https:\/\/codethataint.com\/blog\/?p=5400"},"modified":"2025-01-27T07:09:02","modified_gmt":"2025-01-27T07:09:02","slug":"kafka-commands","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/kafka-commands\/","title":{"rendered":"Kafka Commands"},"content":{"rendered":"<p><strong>To Start Kafka Server<\/strong><\/p>\n<pre>\r\n.\\bin\\windows\\kafka-server-start.bat .\\config\\server.properties\r\n.\\bin\\windows\\kafka-server-stop.bat .\\config\\server.properties\r\n<\/pre>\n<p><strong>To Start Zookeeper Server<\/strong><\/p>\n<pre>\r\n.\\bin\\windows\\zookeeper-server-start.bat .\\config\\zookeeper.properties\r\n.\\bin\\windows\\zookeeper-server-stop.bat .\\config\\zookeeper.properties\r\n<\/pre>\n<p><strong>Create Topic in Kafka with 5 Partition and Replication factor of 1<\/strong><\/p>\n<pre>\r\nkafka-topics.bat  --bootstrap-server localhost:9092 --topic firsttopic --create --partitions 5  --replication-factor 1<\/pre>\n<p><strong>Note:<\/strong> Replication Factor cannot be more than 1 incase of localhost.<\/p>\n<p><strong>List Topics<\/strong><\/p>\n<pre>\r\nkafka-topics.bat  --bootstrap-server localhost:9092 --list<\/pre>\n<p><strong>Describe Topic<\/strong><\/p>\n<pre>\r\nkafka-topics.bat  --bootstrap-server localhost:9092 --topic firsttopic --describe\r\n<\/pre>\n<p><strong>Delete Topic<\/strong><\/p>\n<pre>\r\nkafka-topics.bat  --bootstrap-server localhost:9092 --topic firsttopic --delete\r\n<\/pre>\n<p><strong>Producer to push data into Topic in Kafka<\/strong><\/p>\n<pre>\r\nkafka-console-producer.bat --broker-list localhost:9092 --topic test\r\n<\/pre>\n<p><strong>Producer sending data into Topic as Key:Value pair<\/strong><\/p>\n<pre>\r\nkafka-console-producer.bat --broker-list localhost:9092 --topic firsttopic  --property parse.key=true --property key.separator=:\r\n<\/pre>\n<p><strong>Note:<\/strong><\/p>\n<ol>\n<li>Kafka Topic with same key would end in same Partition <\/li>\n<li>separator should be sent in command to diff between key and value<\/li>\n<\/ol>\n<p><strong>Delete Record in Topic<\/strong><\/p>\n<pre>\r\nkafka-delete-records.bat --bootstrap-server localhost:9092 --offset-json-file .\/offsetfile.json\r\n<\/pre>\n<p>If you try to push data to a topic which doesn&#8217;t exist after 3 attempts the topic would be created.<\/p>\n<p><strong>Consumer to pull data from Topic in Kafka<\/strong><\/p>\n<pre>\r\nkafka-console-consumer.bat --topic test --bootstrap-server localhost:9092 --from-beginning\r\n<\/pre>\n<p><strong>Print Partition, Key, Value in consumer<\/strong><\/p>\n<pre>\r\nkafka-console-consumer.bat --topic thirdtopic --bootstrap-server localhost:9092  --formatter kafka.tools.DefaultMessageFormatter --property print.timestamp=true --property print.key=true --property print.value=true --property print.partition=true --from-beginning\r\n<\/pre>\n<p><strong>Adding consumer to consumer Group <\/strong><\/p>\n<pre>\r\nkafka-console-consumer --bootstrap-server localhost:9092 --topic third_topic --group my-first-application\r\n<\/pre>\n<p><strong>Listing consumer Group <\/strong><\/p>\n<pre>\r\nkafka-consumer-groups.sh  --list --bootstrap-server localhost:9092<\/pre>\n<p><strong>Describing consumer Group <\/strong><\/p>\n<pre>\r\nbin\/kafka-consumer-groups.bat --describe --group mygroup --bootstrap-server localhost:9092\r\n<\/pre>\n<p><strong>Reset Offset in Topic in all partitions<\/strong><\/p>\n<pre>\r\nkafka-console-consumer.bat --topic thirdtopic --bootstrap-server localhost:9092  --formatter kafka.tools.DefaultMessageFormatter --property print.timestamp=true --property print.key=true --property print.value=true --property print.partition=true --from-beginning\r\n<\/pre>\n<p><strong>Note:<\/strong> Resetting Partition makes the consumer to read from the new offset point.<\/p>\n<p>{&#8220;Message&#8221;: &#8220;Hello World from Kafka&#8221;}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To Start Kafka Server .\\bin\\windows\\kafka-server-start.bat .\\config\\server.properties .\\bin\\windows\\kafka-server-stop.bat .\\config\\server.properties To Start Zookeeper Server .\\bin\\windows\\zookeeper-server-start.bat .\\config\\zookeeper.properties .\\bin\\windows\\zookeeper-server-stop.bat .\\config\\zookeeper.properties Create Topic in Kafka with 5 Partition and Replication factor of 1 kafka-topics.bat &#8211;bootstrap-server localhost:9092 &#8211;topic firsttopic &#8211;create &#8211;partitions 5 &#8211;replication-factor 1 Note: Replication Factor cannot be more than 1 incase of localhost. List Topics kafka-topics.bat &#8211;bootstrap-server localhost:9092 &#8211;list&hellip; <a href=\"https:\/\/codethataint.com\/blog\/kafka-commands\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[365],"tags":[],"class_list":["post-5400","post","type-post","status-publish","format-standard","hentry","category-kafka"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5400","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=5400"}],"version-history":[{"count":6,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5400\/revisions"}],"predecessor-version":[{"id":5431,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5400\/revisions\/5431"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=5400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=5400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=5400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}