{"componentChunkName":"component---src-pages-markdown-remark-fields-slug-js","path":"/engineering/quick-kafka-installation/","result":{"data":{"markdownRemark":{"id":"1f3f868c-85de-556a-b0e6-50a8006931c6","excerpt":"In this post, we will look at the step-by-step process for Kafka Installation on Windows. Kafka is an open-source stream-processing software platform and comes…","html":"<p>In this post, we will look at the step-by-step process for Kafka Installation on Windows. Kafka is an open-source stream-processing software platform and comes under the Apache software foundation.</p>\n<h2 id=\"what-is-kafka\" style=\"position:relative;\"><a href=\"#what-is-kafka\" aria-label=\"what is kafka permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>What is Kafka?</strong></h2>\n<p>Kafka is used for real-time streams of data, to collect big data, or to do real-time analysis (or both). Kafka is used with in-memory microservices to provide durability and it can be used to feed events to complex event streaming systems and IoT/IFTTT-style automation systems. </p>\n<h2 id=\"installation-\" style=\"position:relative;\"><a href=\"#installation-\" aria-label=\"installation  permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Installation :</strong></h2>\n<h3 id=\"1-java-setup\" style=\"position:relative;\"><a href=\"#1-java-setup\" aria-label=\"1 java setup permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>1. Java Setup:</h3>\n<p>Kafka requires Java 8 for running. And hence, this is the first step that we should do to install Kafka. To install Java, there are a couple of options. We can go for the Oracle JDK version 8 from the <a href=\"https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html\">Official Oracle Website</a>.</p>\n<h3 id=\"2-kafka--zookeeper-configuration\" style=\"position:relative;\"><a href=\"#2-kafka--zookeeper-configuration\" aria-label=\"2 kafka  zookeeper configuration permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>2. Kafka &#x26; Zookeeper Configuration:</h3>\n<p><strong>Step 1:</strong> Download Apache Kafka from its <a href=\"https://kafka.apache.org/downloads\">Official Site</a>.</p>\n<p><strong>Step 2:</strong> Extract tgz via cmd or from the available tool  to a location of your choice:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">tar -xvzf kafka_2.12-2.4.1.tgz</span></code></pre>\n<p><strong>Step 3:</strong> Copy the path of the Kafka folder. Now go to <em>config</em> inside Kafka folder and open <em>zookeeper.properties</em> file. Copy the path against the field <em>dataDir</em> and add <em>/zookeeper-data</em> to the path.</p>\n<p><img src=\"/256df753510eececf57f6146cb9b9758/zookeeper.webp\">\n<strong>Step 4:</strong> we have to modify the config/server.properties file. Below is the change:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">fileslog.dirs=C:\\kafka\\kafka-logs</span></code></pre>\n<p>Basically, we are pointing the log.dirs to the new folder /data/kafka.</p>\n<h2 id=\"run-kafka-server\" style=\"position:relative;\"><a href=\"#run-kafka-server\" aria-label=\"run kafka server permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Run Kafka Server:</strong></h2>\n<p><strong>Step 1:</strong> Kafka requires Zookeeper to run. Basically, Kafka uses Zookeeper to manage the entire cluster and various brokers. Therefore, a running instance of Zookeeper is a prerequisite to Kafka.</p>\n<p>To start Zookeeper, we can open a PowerShell prompt and execute the below command:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">.\\bin\\windows\\zookeeper-server-start.bat .\\config\\zookeeper.properties</span></code></pre>\n<p>If the command is successful, Zookeeper will start on port 2181.</p>\n<p><strong>Step 2:</strong> Now open another command prompt and change the directory to the kafka folder. Run kafka server using the command: </p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">.\\bin\\windows\\kafka-server-start.bat .\\config\\server.properties</span></code></pre>\n<p><strong>Now your Kafka Server is up and running</strong>, you can create topics to store messages. Also, we can produce or consume data directly from the command prompt.</p>\n<h2 id=\"create-a-kafka-topic\" style=\"position:relative;\"><a href=\"#create-a-kafka-topic\" aria-label=\"create a kafka topic permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Create a Kafka Topic:</strong></h2>\n<ol>\n<li>Open a new command prompt in the location C:\\kafka\\bin\\windows.</li>\n<li>Run the following command:</li>\n</ol>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test</span></code></pre>\n<h2 id=\"creating-kafka-producer\" style=\"position:relative;\"><a href=\"#creating-kafka-producer\" aria-label=\"creating kafka producer permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Creating Kafka Producer:</strong></h2>\n<ol>\n<li>Open a new command prompt in the location C:\\kafka\\bin\\windows</li>\n<li>Run the following command:</li>\n</ol>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kafka-console-producer.bat --broker-list localhost:9092 --topic test</span></code></pre>\n<h2 id=\"creating-kafka-consumer\" style=\"position:relative;\"><a href=\"#creating-kafka-consumer\" aria-label=\"creating kafka consumer permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Creating Kafka Consumer:</strong></h2>\n<ol>\n<li>Open a new command prompt in the location C:\\kafka\\bin\\windows.</li>\n<li>Run the following command:</li>\n</ol>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning</span></code></pre>\n<p>If you see these messages on consumer console,<em>Congratulations!!!</em> you all done. Then you can play with producer and consumer terminal bypassing some Kafka messages.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n</style>","headings":[{"value":"What is Kafka?","depth":2},{"value":"Installation :","depth":2},{"value":"1. Java Setup:","depth":3},{"value":"2. Kafka & Zookeeper Configuration:","depth":3},{"value":"Run Kafka Server:","depth":2},{"value":"Create a Kafka Topic:","depth":2},{"value":"Creating Kafka Producer:","depth":2},{"value":"Creating Kafka Consumer:","depth":2}],"fields":{"slug":"/engineering/quick-kafka-installation/"},"frontmatter":{"metatitle":null,"metadescription":null,"description":null,"title":"Setting Up and Running Apache Kafka on Windows OS","canonical":null,"date":"August 25, 2020","updated_date":null,"tags":["Kafka","Windows"],"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/41484554ead7eb70ade1abe9498282b0/2ad7f/messagelog.webp","srcSet":"/static/41484554ead7eb70ade1abe9498282b0/1c9b5/messagelog.webp 200w,\n/static/41484554ead7eb70ade1abe9498282b0/f1752/messagelog.webp 400w,\n/static/41484554ead7eb70ade1abe9498282b0/2ad7f/messagelog.webp 800w,\n/static/41484554ead7eb70ade1abe9498282b0/e7405/messagelog.webp 1200w,\n/static/41484554ead7eb70ade1abe9498282b0/d3cba/messagelog.webp 1600w,\n/static/41484554ead7eb70ade1abe9498282b0/772d3/messagelog.webp 2700w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Ashish Sharma","github":"ashish8947","bio":"Ashish is a software engineer who continually seeks clean, elegant solutions to business challenges. His lifelong passion for technology drives him to proactively expand horizons, constantly exploring and evaluating new languages, platforms, frameworks and tools.","avatar":null}}}},"pageContext":{"id":"1f3f868c-85de-556a-b0e6-50a8006931c6","fields__slug":"/engineering/quick-kafka-installation/","__params":{"fields__slug":"engineering"}}},"staticQueryHashes":["1171199041","1384082988","1711371485","1753898100","2100481360","229320306","23180105","528864852"]}