{"id":77322,"date":"2018-05-30T07:00:36","date_gmt":"2018-05-30T04:00:36","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=77322"},"modified":"2018-05-29T17:14:18","modified_gmt":"2018-05-29T14:14:18","slug":"spring-apache-kafka-tutorial","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html","title":{"rendered":"Spring Apache Kafka Tutorial"},"content":{"rendered":"<p>In this\u00a0Spring Apache Kafka lesson, we will learn how we can get started with Apache Kafka in a Spring Boot project and start producing and consuming messages on the topic of our choice. Apart from a simple project, we will deep dive into Kafka terminologies and how the concept of partitioning works in Kafka. Let&#8217;s get started.<\/p>\n<h2 id=\"introduction\">1. Introduction<\/h2>\n<p>With the uprise of <a href=\"https:\/\/www.javacodegeeks.com\/2017\/12\/what-are-microservices.html\" target=\"_blank\" rel=\"noopener\">Microservices<\/a>, the necessity of asynchronous communication between the involved services became a mainstream requirement. Actually, that is how Apache Kafka came into existence at <a href=\"https:\/\/engineering.linkedin.com\/blog\/2016\/04\/kafka-ecosystem-at-linkedin\" target=\"_blank\" rel=\"noopener\">LinkedIn<\/a>. The main requirements of the new asynchronous communication system they needed were <strong>message persistence<\/strong> and <strong>high throughput<\/strong>. Once LinkedIn was able to make a project in the face of Kafka, they donated the project to Apache Software foundation where it came to be known as <a href=\"https:\/\/kafka.apache.org\/\" target=\"_blank\" rel=\"noopener\">Apache Kafka<\/a>.<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<dt><a href=\"#what_kafka\">2. What is Apache Kafka?<\/a><\/dt>\n<dt><a href=\"#kafka_terms\">3. Apache Kafka Terminologies<\/a><\/dt>\n<dt><a href=\"#install_kafka\">4. Installing Kafka and Making a Topic<\/a><\/dt>\n<dt><a href=\"#make_project\">5. Making the Spring Boot Project with Maven<\/a><\/dt>\n<dt><a href=\"#add_maven\">6. Adding Maven dependencies<\/a><\/dt>\n<dt><a href=\"#project_structure\">7. Project Structure<\/a><\/dt>\n<dt><a href=\"#add_config\">8. Adding configuration<\/a><\/dt>\n<dt><a href=\"#producer_config\">9. Defining the Producer configuration<\/a><\/dt>\n<dt><a href=\"#consumer_config\">10. Defining the Consumer configuration<\/a><\/dt>\n<dt><a href=\"#spring_boot\">11. Defining the Spring Boot class<\/a><\/dt>\n<dt><a href=\"#run_project\">12. Running the project<\/a><\/dt>\n<dt><a href=\"#kafka_partition\">13. Kafka Partitioning<\/a><\/dt>\n<dt><a href=\"#conclusion\">14. Conclusion<\/a><\/dt>\n<dt><a href=\"#download_code\">15. Download the Source Code<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2 id=\"what_kafka\">2. What is Apache Kafka?<\/h2>\n<p>Kafka was developed at LinkedIn in the year 2010 and it was donated to Apache Software Foundation where it became one of the top projects by 2012. Apache Kafka has three main components in its ecosystem:<\/p>\n<ol>\n<li><strong>Publisher-Subscriber<\/strong>: This component of Kafka is responsible to send and consume data across Kafka Nodes (more on Nodes in coming sections) and the consumer apps which can scale with very high throughput<\/li>\n<li><strong>Kafka Streams<\/strong>: With Kafka streaming API, it is possible to process incoming data into kafka at near real-time<\/li>\n<li><strong>Connect API<\/strong>: With the Connect API, it is possible to integrate many external data sources and data sinks with Kafka<\/li>\n<\/ol>\n<p>For a high-level definition, we can provide a simple definition for Apache Kafka:<\/p>\n<blockquote>\n<p>Apache Kafka is a distributed, fault-tolerant, horizontally-scalable, commit log.<\/p>\n<\/blockquote>\n<p>Let us elaborate what we just said:<\/p>\n<ul>\n<li><strong><em>Distributed<\/em><\/strong>: Kafka is a distributed system where all the messages are replicated across various nodes so that each server is capable of responding to the client for the messages it contains. Also, even if one node fails, other nodes can quickly take over without any downtime<\/li>\n<li><strong><em>Fault-tolerant<\/em><\/strong>: As Kafka does not have a <strong>Single Point of Failure<\/strong>, even if one of the node goes down, the end-user will hardly notice this as the other parts take responsibility of the messages which are lost due to the failed node<\/li>\n<li><strong><em>Horizontally-scalable<\/em><\/strong>: Kafka allows us to add more machines to the cluster with zero downtime. This means that if we start to face lag in messages due to a low number of servers in the cluster, we can quickly add more servers and maintain the performance of the system<\/li>\n<li><strong><em>Commit Log<\/em><\/strong>: A commit log refers to a structure similar to a Linked List. The order of insertion of messages is maintained and data cannot be removed from this log until a threshold time is reached<\/li>\n<\/ul>\n<p>A lot more concepts about Apache Kafka will become clear in the coming sections where we talk about basic terminologies used in\u00a0Apache Kafka lesson.<\/p>\n<h2 id=\"kafka_terms\">3. Apache Kafka Terminologies<\/h2>\n<p>Before we can move ahead with Kafka concepts and sample project, we must understand basic terms related to Apache Kafka. Some of these are:<\/p>\n<ul>\n<li><strong><em>Producer<\/em><\/strong>: This component publish messages to the Kafka cluster<\/li>\n<li><strong><em>Consumer<\/em><\/strong>: This component consume messages from the Kafka cluster<\/li>\n<li><strong><em>Message<\/em><\/strong>: This is the data which is sent by the producer to the cluster<\/li>\n<li><strong><em>Connection<\/em><\/strong>: The producer needs to establesh a TCP connection to publish message. Same is needed in consumer app to consume data from the Kafka cluster<\/li>\n<li><strong><em>Topic<\/em><\/strong>: A Topic is a logical grouping of similar messages. The producer app can publish message to a particular Topic and can consume from a specific Topic<\/li>\n<li><strong><em>Topic Partition<\/em><\/strong>: To scale a topic memory as it can contain a lot of messages, a single Topic is divided into partitions and each partition can live on any node in the cluster, following image shows how message is written into multiple partitions:\n<p><figure id=\"attachment_77332\" aria-describedby=\"caption-attachment-77332\" style=\"width: 781px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-topic-partition.png\"><img decoding=\"async\" class=\"wp-image-77332 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-topic-partition.png\" alt=\"Spring Apache Kafka - Topic partitioning\" width=\"781\" height=\"401\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-topic-partition.png 781w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-topic-partition-300x154.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-topic-partition-768x394.png 768w\" sizes=\"(max-width: 781px) 100vw, 781px\" \/><\/a><figcaption id=\"caption-attachment-77332\" class=\"wp-caption-text\">Topic partitioning in Kafka<\/figcaption><\/figure><\/li>\n<li><strong><em>Replicas<\/em><\/strong>: As we saw in above image about topic partitioning, each message is replicated across various nodes to maintain the order and to prevent data loss when one of the node dies<\/li>\n<li><strong><em>Consumer Groups<\/em><\/strong>: Multiple consumers who are interested in a single topic can be kept in a group which s referred to as Consumer Groups<\/li>\n<li><strong><em>Offset<\/em><\/strong>: Kafka <strong>stores no information<\/strong> about which consumer is going to read what data. Each consumer keeps an <strong>offset<\/strong> value with themselves about what was the last message they read. This means that different consumers can read different messages at the same time<\/li>\n<li><strong><em>Node<\/em><\/strong>: A Node is just a single server in the cluster. We can add virtually any number of nodes in a cluster as we choose<\/li>\n<li><strong><em>Cluster<\/em><\/strong>: A group of nodes is termed as a cluster.<\/li>\n<\/ul>\n<h2 id=\"install_kafka\">4. Installing Kafka and Making a Topic<\/h2>\n<p>To download and install Kafka, we can refer to the Official Kafka guide provided <a href=\"https:\/\/kafka.apache.org\/quickstart\" target=\"_blank\" rel=\"noopener\">here<\/a>. When the Kafka server is up and running, we can create a new topic, named as <code>javacodegeeks<\/code> with the following command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Creating a topic<\/em><\/span><\/p>\n<pre class=\"brush:bash\">bin\/kafka-topics --create \\\r\n --zookeeper localhost:2181 \\\r\n --replication-factor 1 --partitions 1 \\\r\n --topic javacodegeeks\r\n<\/pre>\n<p>We will see the following output once this command executes:<\/p>\n<p><figure id=\"attachment_77335\" aria-describedby=\"caption-attachment-77335\" style=\"width: 626px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-create-topic.png\"><img decoding=\"async\" class=\"wp-image-77335 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-create-topic.png\" alt=\"Spring Apache Kafka - Kafka create topic\" width=\"626\" height=\"141\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-create-topic.png 626w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-create-topic-300x68.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-create-topic-620x141.png 620w\" sizes=\"(max-width: 626px) 100vw, 626px\" \/><\/a><figcaption id=\"caption-attachment-77335\" class=\"wp-caption-text\">Kafka create topic<\/figcaption><\/figure><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2 id=\"make_project\">5. Making the Spring Boot Project with Maven<\/h2>\n<p>We will be using one of the many Maven archetypes to create a sample project for our example. To create the project execute the following command in a directory that you will use as workspace:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Creating a Project<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mvn archetype:generate -DgroupId=com.javacodegeeks.example -DartifactId=JCG-BootKafka-Example -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false\r\n<\/pre>\n<p>If you are running maven for the first time, it will take a few seconds to accomplish the generate command because maven has to download all the required plugins and artifacts in order to make the generation task. Once we run this project, we will see following output and the project will be created:<\/p>\n<p><figure id=\"attachment_77323\" aria-describedby=\"caption-attachment-77323\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/project-creation.png\"><img decoding=\"async\" class=\"wp-image-77323 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/project-creation.png\" alt=\"Spring Apache Kafka - Creating Kafka project\" width=\"820\" height=\"555\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/project-creation.png 820w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/project-creation-300x203.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/project-creation-768x520.png 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-77323\" class=\"wp-caption-text\">Creating Kafka project<\/figcaption><\/figure><\/p>\n<h2 id=\"add_maven\">6. Adding Maven dependencies<\/h2>\n<p>Once you have created the project, feel free to open it in your favourite IDE. Next step is to add appropriate Maven Dependencies to the project. We will work with following dependencies in our project:<\/p>\n<ul>\n<li><code>spring-boot-starter-web<\/code>: This dependency marks this project as a Web project and it adds dependencies in order to create controllers and make Web-related classes.<\/li>\n<li><code>spring-kafka<\/code>: This is the dependency which brings all the Kafka related dependencies into the project classpath<\/li>\n<li><code>spring-boot-starter-test<\/code>: This dependency collects all test related JARs into the project like <a href=\"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html\" target=\"_blank\" rel=\"noopener\">JUnit<\/a> and <a href=\"https:\/\/www.javacodegeeks.com\/2015\/11\/testing-with-mockito.html\" target=\"_blank\" rel=\"noopener\">Mockito<\/a>.<\/li>\n<\/ul>\n<p>Here is the <code>pom.xml<\/code> file with the appropriate dependencies added:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;groupId&gt;com.javacodegeeks.example&lt;\/groupId&gt;\r\n&lt;artifactId&gt;JCG-BootKafka-Example&lt;\/artifactId&gt;\r\n&lt;packaging&gt;jar&lt;\/packaging&gt;\r\n&lt;version&gt;1.0-SNAPSHOT&lt;\/version&gt;\r\n&lt;name&gt;JCG-BootKafka-Example&lt;\/name&gt;\r\n\r\n&lt;parent&gt;\r\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;spring-boot-starter-parent&lt;\/artifactId&gt;\r\n    &lt;version&gt;1.5.10.RELEASE&lt;\/version&gt;\r\n    &lt;relativePath\/&gt; &lt;!-- lookup parent from repository --&gt;\r\n&lt;\/parent&gt;\r\n\r\n&lt;properties&gt;\r\n    &lt;project.build.sourceEncoding&gt;UTF-8&lt;\/project.build.sourceEncoding&gt;\r\n    &lt;project.reporting.outputEncoding&gt;UTF-8&lt;\/project.reporting.outputEncoding&gt;\r\n    &lt;java.version&gt;1.8&lt;\/java.version&gt;\r\n&lt;\/properties&gt;\r\n\r\n&lt;dependencies&gt;\r\n\r\n    &lt;dependency&gt;\r\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\r\n    &lt;\/dependency&gt;\r\n\r\n    &lt;dependency&gt;\r\n        &lt;groupId&gt;org.springframework.kafka&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;spring-kafka&lt;\/artifactId&gt;\r\n        &lt;version&gt;1.1.3.RELEASE&lt;\/version&gt;\r\n    &lt;\/dependency&gt;\r\n\r\n    &lt;dependency&gt;\r\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;spring-boot-starter-test&lt;\/artifactId&gt;\r\n        &lt;scope&gt;test&lt;\/scope&gt;\r\n    &lt;\/dependency&gt;\r\n\r\n&lt;\/dependencies&gt;\r\n\r\n&lt;build&gt;\r\n    &lt;plugins&gt;\r\n        &lt;plugin&gt;\r\n            &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;spring-boot-maven-plugin&lt;\/artifactId&gt;\r\n        &lt;\/plugin&gt;\r\n    &lt;\/plugins&gt;\r\n&lt;\/build&gt;\r\n<\/pre>\n<p>Find the latest Maven dependencies on <a href=\"http:\/\/search.maven.org\/#search|ga|1|g%3A%22org.springframework.boot%22\" target=\"_blank\" rel=\"noopener\">Maven Central<\/a>.<\/p>\n<p>Finally, to understand all the JARs which are added to the project when we added this dependency, we can run a simple Maven command which allows us to see a complete Dependency Tree for a project when we add some dependencies to it. Here is a command which we can use:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Check Dependency Tree<\/em><\/span><\/p>\n<pre class=\"brush:xml\">mvn dependency:tree\r\n<\/pre>\n<p>When we run this command, it will show us the following Dependency Tree:<\/p>\n<p><figure id=\"attachment_77340\" aria-describedby=\"caption-attachment-77340\" style=\"width: 759px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-dependency.png\"><img decoding=\"async\" class=\"wp-image-77340 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-dependency.png\" alt=\"Spring Apache Kafka - Checking Dependency\" width=\"759\" height=\"1058\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-dependency.png 759w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-dependency-215x300.png 215w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-dependency-735x1024.png 735w\" sizes=\"(max-width: 759px) 100vw, 759px\" \/><\/a><figcaption id=\"caption-attachment-77340\" class=\"wp-caption-text\">Checking Dependency<\/figcaption><\/figure><\/p>\n<p>Noticed something? So many dependencies were added by just adding four dependencies to the project. Spring Boot collects all related dependencies itself and leave nothing for us in that matter. The biggest advantage is that <strong>all these dependencies are guranteed to be copatible with each other<\/strong>.<\/p>\n<h2 id=\"project_structure\">7. Project Structure<\/h2>\n<p>Before we move on and start working on the code for the project, let\u2019s present here the project structure we will have once we\u2019re finished adding all the code to the project:<\/p>\n<p><figure id=\"attachment_77342\" aria-describedby=\"caption-attachment-77342\" style=\"width: 405px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/project-structure.png\"><img decoding=\"async\" class=\"wp-image-77342 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/project-structure.png\" alt=\"Spring Apache Kafka - Project Structure\" width=\"405\" height=\"435\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/project-structure.png 405w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/project-structure-279x300.png 279w\" sizes=\"(max-width: 405px) 100vw, 405px\" \/><\/a><figcaption id=\"caption-attachment-77342\" class=\"wp-caption-text\">Project Structure<\/figcaption><\/figure><\/p>\n<p>We have divided the project into multiple packages so that the principle of <a href=\"https:\/\/stackoverflow.com\/questions\/98734\/what-is-separation-of-concerns\" target=\"_blank\" rel=\"noopener\">separation of concern<\/a> is followed and code remains modular.<\/p>\n<h2 id=\"add_config\">8. Adding configuration<\/h2>\n<p>Before we can start writing code for our project, we need to provide some properties in the <code>application.properties<\/code> file of our Spring Boot project:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>application.properties<\/em><\/span><\/p>\n<pre class=\"brush:bash\">#Kafka Topic\r\nmessage.topic.name=javacodegeeks\r\n\r\nspring.kafka.bootstrap-servers=localhost:9092\r\n\r\n#Unique String which identifies which consumer group this consumer belongs to\r\nspring.kafka.consumer.group-id=jcg-group\r\n<\/pre>\n<p>These are some properties which we will be using in our project as the topic and group ID for the message we will publish and consume. Also, <code>9092<\/code> is the default port for Apache Kafka. Note that we could have defined multiple topics here as well with different name for the keys.<\/p>\n<h2 id=\"producer_config\">9. Defining the Producer configuration<\/h2>\n<p>We will start by defining the configuration for a Producer. The only property we need to define mandatorily for a Kafka Producer is the address for Kafka server with its port.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>KafkaProducerConfig.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.example.config;\r\n\r\nimport org.apache.kafka.clients.producer.ProducerConfig;\r\nimport org.apache.kafka.common.serialization.StringSerializer;\r\nimport org.springframework.beans.factory.annotation.Value;\r\nimport org.springframework.context.annotation.Bean;\r\nimport org.springframework.context.annotation.Configuration;\r\nimport org.springframework.kafka.core.DefaultKafkaProducerFactory;\r\nimport org.springframework.kafka.core.KafkaTemplate;\r\nimport org.springframework.kafka.core.ProducerFactory;\r\n\r\nimport java.util.HashMap;\r\nimport java.util.Map;\r\n\r\n@Configuration\r\npublic class KafkaProducerConfig {\r\n\r\n    @Value(\"${spring.kafka.bootstrap-servers}\")\r\n    private String bootstrapAddress;\r\n\r\n    @Bean\r\n    public ProducerFactory&lt;String, String&gt; producerFactory() {\r\n        Map&lt;String, Object&gt; configProps = new HashMap&lt;&gt;();\r\n        configProps.put(\r\n            ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);\r\n        configProps.put(\r\n            ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);\r\n        configProps.put(\r\n            ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);\r\n        return new DefaultKafkaProducerFactory&lt;&gt;(configProps);\r\n    }\r\n\r\n    @Bean\r\n    public KafkaTemplate&lt;String, String&gt; kafkaTemplate() {\r\n        return new KafkaTemplate&lt;&gt;(producerFactory());\r\n    }\r\n}\r\n<\/pre>\n<p>Although above class definition is pretty simple, we still have some points which we need to understand:<\/p>\n<ul>\n<li><code>@Configuration<\/code>: This class is defined as a configuration class which means that this class will be picked up by Spring Boot automatically and all beans defined inside this class will be managed by Spring container automatically.<\/li>\n<li>We defined a bean for <code>ProducerFactory<\/code> which takes input as various properties like the Kafka server address and other serialization properties which hels to code and decode the message sent through the Kafka producer bean.<\/li>\n<li>Finally, we defined a bean for <code>KafkaTemplate<\/code> which is the actual API object which will be used to publish the message on a Kafka topic.<\/li>\n<\/ul>\n<h2 id=\"consumer_config\">10. Defining the Consumer configuration<\/h2>\n<p>As we are making Kafka producer and consumer in the same app for demonstration purposes, we will also define a consumer config class which will just contain basic properties for a Kafka consumer. This class can be put inside any project which isn&#8217;t a producer and only a Kafka consumer as well without any changes. Let&#8217;s look at the configuration definition:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>KafkaConsumerConfig.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.example.config;\r\n\r\nimport org.apache.kafka.clients.consumer.ConsumerConfig;\r\nimport org.apache.kafka.common.serialization.StringDeserializer;\r\nimport org.springframework.beans.factory.annotation.Value;\r\nimport org.springframework.context.annotation.Bean;\r\nimport org.springframework.context.annotation.Configuration;\r\nimport org.springframework.kafka.annotation.EnableKafka;\r\nimport org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;\r\nimport org.springframework.kafka.core.ConsumerFactory;\r\nimport org.springframework.kafka.core.DefaultKafkaConsumerFactory;\r\n\r\nimport java.util.HashMap;\r\nimport java.util.Map;\r\n\r\n@EnableKafka\r\n@Configuration\r\npublic class KafkaConsumerConfig {\r\n\r\n    @Value(\"${spring.kafka.bootstrap-servers}\")\r\n    private String bootstrapAddress;\r\n\r\n    @Value(\"${spring.kafka.consumer.group-id}\")\r\n    private String groupId;\r\n\r\n    @Bean\r\n    public ConsumerFactory&lt;String, String&gt; consumerFactory() {\r\n        Map&lt;String, Object&gt; props = new HashMap&lt;&gt;();\r\n        props.put(\r\n                ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);\r\n        props.put(\r\n                ConsumerConfig.GROUP_ID_CONFIG, groupId);\r\n        props.put(\r\n                ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);\r\n        props.put(\r\n                ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);\r\n        return new DefaultKafkaConsumerFactory&lt;&gt;(props);\r\n    }\r\n\r\n    @Bean\r\n    public ConcurrentKafkaListenerContainerFactory&lt;String, String&gt; kafkaListenerContainerFactory() {\r\n        ConcurrentKafkaListenerContainerFactory&lt;String, String&gt; factory\r\n                = new ConcurrentKafkaListenerContainerFactory&lt;&gt;();\r\n        factory.setConsumerFactory(consumerFactory());\r\n        return factory;\r\n    }\r\n}\r\n<\/pre>\n<p>The configuration we provided is very similar to the producer configuration. The only difference to note here is:<\/p>\n<ul>\n<li>We defined a <code>ConsumerFactory<\/code> class object bean which considers the Kafka server address and the consumer group ID as well which this Kafka consumer app belongs to. We have provided a unique String to the consumer as only a unique string is acceptable<\/li>\n<li>Finally, we defined a <code>ConcurrentKafkaListenerContainerFactory<\/code> which makes sure that this consumer application can consume Kafka messages at a concurrent pace and can give a consistent throughput even when published messages are high in number.<\/li>\n<\/ul>\n<h2 id=\"spring_boot\">11. Defining the Spring Boot class<\/h2>\n<p>At the final stage, we will make the Spring Boot class with which we can publish a message, consume the message on the same topic. Here is the class definition for the main class:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>KafkaApp.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.example;\r\n\r\nimport org.slf4j.Logger;\r\nimport org.slf4j.LoggerFactory;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.beans.factory.annotation.Value;\r\nimport org.springframework.boot.CommandLineRunner;\r\nimport org.springframework.boot.SpringApplication;\r\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\r\nimport org.springframework.kafka.annotation.KafkaListener;\r\nimport org.springframework.kafka.core.KafkaTemplate;\r\n\r\n@SpringBootApplication\r\npublic class KafkaApp implements CommandLineRunner {\r\n\r\n    private static final Logger LOG = LoggerFactory.getLogger(\"KafkaApp\");\r\n\r\n    @Value(\"${message.topic.name}\")\r\n    private String topicName;\r\n\r\n    private final KafkaTemplate&lt;String, String&gt; kafkaTemplate;\r\n\r\n    @Autowired\r\n    public KafkaApp(KafkaTemplate&lt;String, String&gt; kafkaTemplate) {\r\n        this.kafkaTemplate = kafkaTemplate;\r\n    }\r\n\r\n    public static void main(String[] args) {\r\n        SpringApplication.run(KafkaApp.class, args);\r\n    }\r\n\r\n    @Override\r\n    public void run(String... strings) {\r\n        kafkaTemplate.send(topicName, \"Hello Geek!\");\r\n        LOG.info(\"Published message to topic: {}.\", topicName);\r\n    }\r\n\r\n    @KafkaListener(topics = \"javacodegeeks\", group = \"jcg-group\")\r\n    public void listen(String message) {\r\n        LOG.info(\"Received message in JCG group: {}\", message);\r\n    }\r\n\r\n}\r\n<\/pre>\n<p>We have used an interface <code>CommandLineRunner<\/code> to make this class run code with which we can test the producer and config class code we wrote. In this class, we publish a message to the specified topic and listen for it in the listener method we defined in the same class.<\/p>\n<p>In the next section, we will run our project with a simple Maven command.<\/p>\n<h2 id=\"run_project\">12. Running the project<\/h2>\n<p>Now that the main class definition is done, we can run our project. Running the application is easy with maven, just use the following command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Running the Project<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mvn spring-boot:run\r\n<\/pre>\n<p>Once we execute the above command, we will see that a message has been published on the specified topic and same app consumed the message as well:<\/p>\n<p><figure id=\"attachment_77339\" aria-describedby=\"caption-attachment-77339\" style=\"width: 786px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-project-running.png\"><img decoding=\"async\" class=\"wp-image-77339 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-project-running.png\" alt=\"Spring Apache Kafka - Running project\" width=\"786\" height=\"521\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-project-running.png 786w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-project-running-300x199.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-project-running-768x509.png 768w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/a><figcaption id=\"caption-attachment-77339\" class=\"wp-caption-text\">Running Spring Boot Kafka project<\/figcaption><\/figure><\/p>\n<h2 id=\"kafka_partition\">13. Kafka Partitioning<\/h2>\n<p>As a final concept, we will touch upon how Topic partitioning is done in Apache Kafka. We will start with a very simple illustrative image which shows how leaders exist in a Topic partition:<\/p>\n<p><figure id=\"attachment_77345\" aria-describedby=\"caption-attachment-77345\" style=\"width: 591px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-topic-partition-blocks.png\"><img decoding=\"async\" class=\"wp-image-77345 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-topic-partition-blocks.png\" alt=\"Spring Apache Kafka - Topic Partitioning\" width=\"591\" height=\"411\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-topic-partition-blocks.png 591w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/kafka-topic-partition-blocks-300x209.png 300w\" sizes=\"(max-width: 591px) 100vw, 591px\" \/><\/a><figcaption id=\"caption-attachment-77345\" class=\"wp-caption-text\">Topic Partitioning<\/figcaption><\/figure><\/p>\n<p>When a write happens for a topic at a position for which Partition 0 in the Broker 0 is the leader, this data is replicated across the nodes so that the message remains safe. This means that message will be replicated across Partition 0 for all three brokers shown in the image above.<\/p>\n<p>The replication process in Kafka is done in parallel by multiple threads being opened by the node. As the threads are opened to exploit parallelism as much as possible, a very high throughput system is achieved in Kafka. After a message is replicated a certain number of times, <strong>a write is called to be accepted<\/strong> but the replication of message continues until the replication factor is achieved for the data.<\/p>\n<h2 id=\"conclusion\">14. Conclusion<\/h2>\n<p>In this lesson, we looked at how easy and quick it is to construct a Spring Boot app with Apache Kafka integrated into it. Apache Kafka has grown from a simple Apache project to a production-grade project which can manage millions of request each second when deployed with the correct number of nodes in its cluster, assigned proper memory and managed correctly through Zookeeper. Apache Kafka is one of the most promising skill to have in a software engineer jobs and can cover many use cases like website-tracking, real-time messaging application and much more.<\/p>\n<p>The scale at which Apache Kafka can manage messages on its topics and partitions is really humungous and the architecture route it takes to become so much scalable is inspiring to many other projects. The scailability and real-time processing speed it promises it offers makes sure that it solves many of your problems in projects which needs to scale very much.<\/p>\n<h2 id=\"download_code\">15. Download the Source Code<\/h2>\n<p>This was an example of Apache Kafka integration with Spring Framework.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <strong><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/JCG-BootKafka-Example.zip\" target=\"_blank\" rel=\"noopener\">JCG-BootKafka-Example<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this\u00a0Spring Apache Kafka lesson, we will learn how we can get started with Apache Kafka in a Spring Boot project and start producing and consuming messages on the topic of our choice. Apart from a simple project, we will deep dive into Kafka terminologies and how the concept of partitioning works in Kafka. Let&#8217;s &hellip;<\/p>\n","protected":false},"author":20016,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[940,30,1754,854],"class_list":["post-77322","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-apache-kafka","tag-spring","tag-spring-apache-kafka","tag-spring-boot"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring Apache Kafka Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this\u00a0Spring Apache Kafka lesson, we will learn how we can get started with Apache Kafka in a Spring Boot project and start producing and consuming\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Apache Kafka Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this\u00a0Spring Apache Kafka lesson, we will learn how we can get started with Apache Kafka in a Spring Boot project and start producing and consuming\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2018-05-30T04:00:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Shubham Aggarwal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shubham Aggarwal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/spring-apache-kafka-tutorial.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/spring-apache-kafka-tutorial.html\"},\"author\":{\"name\":\"Shubham Aggarwal\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/0953481a8babbb7a63907edb41f357ad\"},\"headline\":\"Spring Apache Kafka Tutorial\",\"datePublished\":\"2018-05-30T04:00:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/spring-apache-kafka-tutorial.html\"},\"wordCount\":2207,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/spring-apache-kafka-tutorial.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"keywords\":[\"Apache Kafka\",\"Spring\",\"Spring Apache Kafka\",\"Spring Boot\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/spring-apache-kafka-tutorial.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/spring-apache-kafka-tutorial.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/spring-apache-kafka-tutorial.html\",\"name\":\"Spring Apache Kafka Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/spring-apache-kafka-tutorial.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/spring-apache-kafka-tutorial.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2018-05-30T04:00:36+00:00\",\"description\":\"In this\u00a0Spring Apache Kafka lesson, we will learn how we can get started with Apache Kafka in a Spring Boot project and start producing and consuming\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/spring-apache-kafka-tutorial.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/spring-apache-kafka-tutorial.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/spring-apache-kafka-tutorial.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"java-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/spring-apache-kafka-tutorial.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Spring Apache Kafka Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/0953481a8babbb7a63907edb41f357ad\",\"name\":\"Shubham Aggarwal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g\",\"caption\":\"Shubham Aggarwal\"},\"description\":\"Shubham is a Java EE Engineer with about 3 years of experience in building quality products with Spring Boot, Spring Data, AWS, Kafka, PrestoDB.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sbmaggarwal\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/shubham-aggarwal\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Apache Kafka Tutorial - Java Code Geeks","description":"In this\u00a0Spring Apache Kafka lesson, we will learn how we can get started with Apache Kafka in a Spring Boot project and start producing and consuming","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html","og_locale":"en_US","og_type":"article","og_title":"Spring Apache Kafka Tutorial - Java Code Geeks","og_description":"In this\u00a0Spring Apache Kafka lesson, we will learn how we can get started with Apache Kafka in a Spring Boot project and start producing and consuming","og_url":"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2018-05-30T04:00:36+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Shubham Aggarwal","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Shubham Aggarwal","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html"},"author":{"name":"Shubham Aggarwal","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/0953481a8babbb7a63907edb41f357ad"},"headline":"Spring Apache Kafka Tutorial","datePublished":"2018-05-30T04:00:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html"},"wordCount":2207,"commentCount":3,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","keywords":["Apache Kafka","Spring","Spring Apache Kafka","Spring Boot"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html","url":"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html","name":"Spring Apache Kafka Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2018-05-30T04:00:36+00:00","description":"In this\u00a0Spring Apache Kafka lesson, we will learn how we can get started with Apache Kafka in a Spring Boot project and start producing and consuming","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","width":150,"height":150,"caption":"java-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/spring-apache-kafka-tutorial.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Spring Apache Kafka Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/0953481a8babbb7a63907edb41f357ad","name":"Shubham Aggarwal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g","caption":"Shubham Aggarwal"},"description":"Shubham is a Java EE Engineer with about 3 years of experience in building quality products with Spring Boot, Spring Data, AWS, Kafka, PrestoDB.","sameAs":["https:\/\/www.linkedin.com\/in\/sbmaggarwal\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/shubham-aggarwal"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/77322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/20016"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=77322"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/77322\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=77322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=77322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=77322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}