<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Divyaksh</title>
    <description>The latest articles on DEV Community by Divyaksh (@divyakshshukla).</description>
    <link>https://dev.to/divyakshshukla</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F487534%2F994be961-a1a7-4cc9-9f84-713b2c0a2b3c.jpeg</url>
      <title>DEV Community: Divyaksh</title>
      <link>https://dev.to/divyakshshukla</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/divyakshshukla"/>
    <language>en</language>
    <item>
      <title>Installing Apache Kafka (Confluent edition)</title>
      <dc:creator>Divyaksh</dc:creator>
      <pubDate>Fri, 04 Feb 2022 17:28:52 +0000</pubDate>
      <link>https://dev.to/divyakshshukla/installing-apache-kafka-confluent-edition-39g1</link>
      <guid>https://dev.to/divyakshshukla/installing-apache-kafka-confluent-edition-39g1</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Download&lt;/li&gt;
&lt;li&gt;1. Start zookeeper&lt;/li&gt;
&lt;li&gt;2. Create a Kafka Broker&lt;/li&gt;
&lt;li&gt;
3. Create a Kafka topic

&lt;ul&gt;
&lt;li&gt;Listing the topics&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;4. Create a Kafka Producer&lt;/li&gt;
&lt;li&gt;5. Create a Kafka Consumer&lt;/li&gt;
&lt;li&gt;LOGS (DEBUG)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Download
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-O&lt;/span&gt; http://packages.confluent.io/archive/5.4/confluent-community-5.4.0-2.12.zip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  1. Start zookeeper
&lt;/h2&gt;

&lt;p&gt;Navigate to the folder where confluent is installed. For me it was &lt;code&gt;/home/divyaksh/Downloads/software/confluent-5.4.0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Linux&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bin/zookeeper-server-start etc/kafka/zookeeper.properties
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Windows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="kd"&gt;bin&lt;/span&gt;\windows\zookeeper&lt;span class="na"&gt;-server-start&lt;/span&gt;.bat &lt;span class="kd"&gt;etc&lt;/span&gt;\kafka\zookeeper.properties
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Error&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Occurs if something is missing. I don't know what do do if this happens in linux.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Classpath is empty. Please build the project first using 'gradlew jarAll'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to &lt;code&gt;bin/kafka-run-class&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Add some code. Go to a line above this script (&lt;strong&gt;do not delete anything&lt;/strong&gt;)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="c"&gt;rem Classpath addition for core&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;add the below code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="c"&gt;rem Classpath addition for LSB style path&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;exist&lt;/span&gt; &lt;span class="nv"&gt;%BASE_DIR%&lt;/span&gt;\share\java\kafka\&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;call&lt;/span&gt; &lt;span class="nl"&gt;:concat&lt;/span&gt; &lt;span class="nv"&gt;%BASE_DIR%&lt;/span&gt;\share\java\kafka\&lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Create a Kafka Broker
&lt;/h2&gt;

&lt;p&gt;Linux&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bin/kafka-server-start etc/kafka/server.properties
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Windows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="kd"&gt;bin&lt;/span&gt;\windows\kafka&lt;span class="na"&gt;-server-start&lt;/span&gt;.bat &lt;span class="kd"&gt;etc&lt;/span&gt;\kafka\server.properties
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Create a Kafka topic
&lt;/h2&gt;

&lt;p&gt;Linux&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bin/kafka-topics &lt;span class="nt"&gt;--create&lt;/span&gt; &lt;span class="nt"&gt;--topic&lt;/span&gt; sampleTopic &lt;span class="nt"&gt;--partitions&lt;/span&gt; 1 &lt;span class="nt"&gt;--replication-factor&lt;/span&gt; 1 &lt;span class="nt"&gt;--bootstrap-server&lt;/span&gt; localhost:9092
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Windows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="kd"&gt;bin&lt;/span&gt;\windows\kafka&lt;span class="na"&gt;-topics&lt;/span&gt;.bat &lt;span class="na"&gt;--create --topic &lt;/span&gt;&lt;span class="kd"&gt;sampleTopic&lt;/span&gt; &lt;span class="na"&gt;--partitions &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="na"&gt;--replication-factor &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="na"&gt;--bootstrap-server &lt;/span&gt;&lt;span class="kd"&gt;localhost&lt;/span&gt;:9092
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Warning&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thus, create topics with names not haveing &lt;code&gt;.&lt;/code&gt; or &lt;code&gt;_&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;--partition&lt;/code&gt; n:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Number of partitions

&lt;ul&gt;
&lt;li&gt;How much storage is needed (how big my message is)&lt;/li&gt;
&lt;li&gt;Nature of parallel processing&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here we have a simple workload of a single producer and a single consumer (n = 1)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;--replication-factor&lt;/code&gt; f : number of copies of each partition in the cluster. You create multiple brokers and a in each you make a copy of the messages. Higher the replication factor, more number of copies. No sense of keeping f=10 when there is only 1 broker. in our example f = 1&lt;/p&gt;

&lt;p&gt;&lt;code&gt;--bootstrap-server&lt;/code&gt;: it takes 2 arguments &lt;code&gt;ip-address&lt;/code&gt; and &lt;code&gt;port-number&lt;/code&gt;. In our example we are running the zookeeper on local machine and the default port number of zookeeper is &lt;code&gt;9092&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Listing the topics
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ bin/kafka-topics --list --bootstrap-server localhost:9092
__confluent.support.metrics
sampleTopic
sample_topic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Create a Kafka Producer
&lt;/h2&gt;

&lt;p&gt;Linux&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bin/kafka-console-producer &lt;span class="nt"&gt;--topic&lt;/span&gt; sampleTopic &lt;span class="nt"&gt;--broker-list&lt;/span&gt; localhost:9092  &amp;lt; &amp;lt;path to some file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Windows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="kd"&gt;bin&lt;/span&gt;\windows\kafka&lt;span class="na"&gt;-console-producer&lt;/span&gt;.bat &lt;span class="na"&gt;--topic &lt;/span&gt;&lt;span class="kd"&gt;sampleTopic&lt;/span&gt; &lt;span class="na"&gt;--broker-list &lt;/span&gt;&lt;span class="kd"&gt;localhost&lt;/span&gt;:9092 &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;path&lt;/span&gt; &lt;span class="kd"&gt;to&lt;/span&gt; &lt;span class="kd"&gt;some&lt;/span&gt; &lt;span class="kd"&gt;file&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;--broker-list&lt;/code&gt;: same as &lt;code&gt;--bootstrap-server&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTICE&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ bin/kafka-console-producer --help
This tool helps to read data from standard input and publish it to Kafka.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So you have to input the file using &lt;code&gt;&amp;lt;&lt;/code&gt; operator before giving &lt;code&gt;&amp;lt;path to some file&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Create a Kafka Consumer
&lt;/h2&gt;

&lt;p&gt;Linux&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bin/kafka-console-consumer &lt;span class="nt"&gt;--topic&lt;/span&gt; sampleTopic &lt;span class="nt"&gt;--bootstrap-server&lt;/span&gt; localhost:9092 &lt;span class="nt"&gt;-from-beginning&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Windows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="kd"&gt;bin&lt;/span&gt;\windows\kafka&lt;span class="na"&gt;-console-consumer&lt;/span&gt;.bat &lt;span class="na"&gt;--topic &lt;/span&gt;&lt;span class="kd"&gt;sampleTopic&lt;/span&gt; &lt;span class="na"&gt;--bootstrap-server &lt;/span&gt;&lt;span class="kd"&gt;localhost&lt;/span&gt;:9092 &lt;span class="na"&gt;-from-beginning
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;OUTPUT&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ bin/kafka-console-consumer --topic sampleTopic --bootstrap-server localhost:9092 -from-beginning
To: divyaksh.shukla@gmail.com
From: ideapad.divyaksh@gmail.com
Subject: This is a test email from msmtp

MSMTP says hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I had given a test email file as an input to the producer.&lt;/p&gt;

&lt;h2&gt;
  
  
  LOGS (DEBUG)
&lt;/h2&gt;

&lt;p&gt;You can find the logs at &lt;code&gt;/tmp/kafka-logs/&lt;/code&gt; to debug kafka. Windows &lt;code&gt;C:\tmp\kafka-logs\&lt;/code&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>machinelearning</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
