

{"id":14717,"date":"2018-04-28T12:15:49","date_gmt":"2018-04-28T06:45:49","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=14717"},"modified":"2023-08-17T18:39:06","modified_gmt":"2023-08-17T13:09:06","slug":"kafka-producer","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/kafka-producer\/","title":{"rendered":"Apache Kafka Producer For Beginners"},"content":{"rendered":"<p><span style=\"font-weight: 400\">In our last Kafka Tutorial, we discussed <strong>Kafka Cluster<\/strong>. Today, we will discuss Kafka Producer with the example. Moreover, we will see KafkaProducer API and Producer API. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Also, we will learn configurations settings in Kafka Producer. At last, we will discuss simple producer application in Kafka Producer tutorial. In order to publish messages to an <strong>Apache Kafka<\/strong> topic, we use Kafka Producer.\u00a0<\/span><\/p>\n<p>So, let&#8217;s explore Apache Kafka Producer in detail.<\/p>\n<h3><span style=\"font-weight: 400\">What is Kafka Producer?<\/span><\/h3>\n<p>A Kafka Producer in Apache Kafka is a component in charge of creating and transmitting data to Kafka topics. Kafka is a distributed streaming technology made to deal with large amounts of data quickly. Building scalable and fault-tolerant data pipelines is made much easier by the ability to publish and subscribe to data as streams.<\/p>\n<p>A client application called the Kafka Producer commonly sends messages or data records to Kafka topics.<\/p>\n<p>Kafka is a popular option for developing scalable and real-time data streaming systems because of its design, which assures that Producers can transmit data to Brokers rapidly and Brokers can disseminate the data to Consumers in real-time.<\/p>\n<p><span style=\"font-weight: 400\">Further, the picture below is showing the working of Apache Kafka Producer.<\/span><\/p>\n<div id=\"attachment_14804\" style=\"width: 665px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Apache-Kafka-Producer-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-14804\" class=\"wp-image-14804 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Apache-Kafka-Producer-1.png\" alt=\"Kafka Producer - Apache Kafka Producer Working\" width=\"655\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Apache-Kafka-Producer-1.png 655w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Apache-Kafka-Producer-1-150x144.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Apache-Kafka-Producer-1-300x288.png 300w\" sizes=\"auto, (max-width: 655px) 100vw, 655px\" \/><\/a><p id=\"caption-attachment-14804\" class=\"wp-caption-text\">Kafka Producer &#8211; Apache Kafka Producer Working<\/p><\/div>\n<p>There are some API\u2019s available in Kafka Producer Client.<\/p>\n<h3><span style=\"font-weight: 400\">KafkaProducer API<\/span><\/h3>\n<p><span style=\"font-weight: 400\">However, to publish a stream of records to one or more <strong>Kafka topics<\/strong>, this Kafka Producer API permits to an application. Moreover, its central part is KafkaProducer class. Basically, with the following methods, this class offers an option to connect a Kafka broker in its constructor:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">In order to send messages asynchronously to a topic, KafkaProducer class provides send method. So, the <strong>signature<\/strong> of send() is:<\/span><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">producer.send(new ProducerRecord&lt;byte[],byte[]&gt;(topic,\r\npartition, key1, value1) , callback);<\/pre>\n<ul>\n<li><b>ProducerRecord<\/b><span style=\"font-weight: 400\"> \u2212 Generally, the producer manages a buffer of records waiting to be sent.<\/span><\/li>\n<li style=\"font-weight: 400\"><b>Callback<\/b><span style=\"font-weight: 400\"> \u2212 When the record has been acknowledged by the server, a user-supplied callback to execute. <\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\"><strong>Note<\/strong>: Here, null indicates no callback.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Moreover, to ensure all previously sent messages have been actually completed, KafkaProducer class provides a flush method. So, the <strong>syntax<\/strong> of the flush method is \u2212<\/span><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">public void flush()<\/pre>\n<ul>\n<li>\u00a0<span style=\"font-weight: 400\">Also, to get the partition metadata for a given topic, KafkaProducer class provides the partition for method. Moreover, we can use it for custom partitioning. So, the <strong>signature<\/strong> of this method is:<\/span><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">public Map metrics()<\/pre>\n<p><span style=\"font-weight: 400\">In this way, this method returns the map of internal metrics maintained by the producer.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><b>public void close()<\/b><span style=\"font-weight: 400\"> \u2212 It also offers a close method blocks until all previously sent requests are completed.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400\">Producer API<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Producer class is the central part of the Kafka Producer API. By the following methods, it offers an option to connect the Kafka broker in its constructor.<\/span><\/p>\n<h4><span style=\"font-weight: 400\">a. Kafka\u00a0<\/span>Producer Class<\/h4>\n<p><span style=\"font-weight: 400\">Basically, to send messages to either single or multiple topics, the producer class offers an send method. The following are the <strong>signatures<\/strong> we can use for it.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">public void send(KeyedMessaget&lt;k,v&gt; message)<\/pre>\n<p><strong>\u00a0&#8211; <\/strong>sends the data to a single topic<strong>,\u00a0<\/strong>partitioned by key using either sync or async producer.<\/p>\n<pre class=\"EnlighterJSRAW\">public void send(List&lt;KeyedMessage&lt;k,v&gt;&gt;messages)<\/pre>\n<p>&#8211; sends data to multiple topics.<\/p>\n<pre class=\"EnlighterJSRAW\">Properties prop = new Properties();\r\nprop.put(producer.type,\u201dasync\u201d)\r\nProducerConfig config = new ProducerConfig(prop);<\/pre>\n<p><span style=\"font-weight: 400\">However, there are two types of producers, such as <strong>Sync<\/strong> and <strong>Async<\/strong>.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Although, to Sync producer, the same API configuration applies. There is only one difference in both: <\/span><span style=\"font-weight: 400\">Sync producer sends messages directly but in the background whereas, when we want higher throughput, we prefer the Async producer.<\/span><\/p>\n<p><span style=\"font-weight: 400\"> However, an Async producer does not have a callback for send() to register error handlers in the previous releases like 0.8. It is only available in the current release of 0.9. <\/span><\/p>\n<h4>b. Public Void Close()<\/h4>\n<p><span style=\"font-weight: 400\">In order to close the producer pool connections to all <strong>Kafka brokers<\/strong>, producer class offers a public void close() method.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Configuration Settings For Kafka Producer API<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Here, we are listing the Kafka Producer API\u2019s main configuration settings: <\/span><\/p>\n<p><strong>a.\u00a0<span style=\"font-family: Verdana, Geneva, sans-serif\">client.id<\/span><\/strong><br \/>\n<span style=\"font-weight: 400\">It identifies producer application.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>b.\u00a0<\/strong><\/span><strong><span style=\"font-family: Verdana, Geneva, sans-serif\">producer.type<\/span><\/strong><br \/>\n<span style=\"font-weight: 400\">Either sync or async.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>c.\u00a0<\/strong><\/span><strong><span style=\"font-family: Verdana, Geneva, sans-serif\">acks<\/span><\/strong><br \/>\n<span style=\"font-weight: 400\">Basically, it controls the criteria for producer requests that\u00a0are considered complete. <\/span><\/p>\n<p><strong>d.\u00a0<span style=\"font-family: Verdana, Geneva, sans-serif\">retries<\/span><\/strong><br \/>\n<span style=\"font-weight: 400\">\u201cRetries\u201d means if somehow producer request fails, then automatically retry with the specific value. <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>e.\u00a0<\/strong><\/span><strong><span style=\"font-family: Verdana, Geneva, sans-serif\">bootstrap.servers<\/span><\/strong><br \/>\n<span style=\"font-weight: 400\">It bootstraps list of brokers. <\/span><\/p>\n<p><strong>f.\u00a0<span style=\"font-family: Verdana, Geneva, sans-serif\">linger.ms<\/span><\/strong><br \/>\n<span style=\"font-weight: 400\">Basically, we can set linger.ms to something greater than some value, if we want to reduce the number of requests. <\/span><\/p>\n<p><strong>g.\u00a0<span style=\"font-family: Verdana, Geneva, sans-serif\">key.serializer<\/span><\/strong><br \/>\n<span style=\"font-weight: 400\">It is a key for the serializer interface. <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>h.\u00a0<\/strong><\/span><strong><span style=\"font-family: Verdana, Geneva, sans-serif\">value.serializer<\/span><\/strong><br \/>\n<span style=\"font-weight: 400\">A value for the serializer interface.<\/span><\/p>\n<p><strong>i.\u00a0<span style=\"font-family: Verdana, Geneva, sans-serif\">batch.size<\/span><\/strong><br \/>\n<span style=\"font-weight: 400\">Simply, Buffer size. <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>j.\u00a0<\/strong><\/span><strong><span style=\"font-family: Verdana, Geneva, sans-serif\">buffer.memory<\/span><\/strong><br \/>\n<span style=\"font-weight: 400\">\u201cbuffer.memory\u201d controls the total amount of memory available to the producer for buffering.<\/span><\/p>\n<h3>ProducerRecord API<\/h3>\n<p><span style=\"font-weight: 400\">By using the following signature, it is a key\/value pair that is sent to the Kafka cluster. ProducerRecord class constructor is for creating a record with partition, key and value pairs.<\/span><br \/>\n<b>public ProducerRecord (string topic, int partition, k key, v value)<\/b><\/p>\n<ol>\n<li><span style=\"font-weight: 400\"> Topic \u2212 user-defined topic name that will append to record.<\/span><\/li>\n<li><span style=\"font-weight: 400\">Partition \u2212 partition count.<\/span><\/li>\n<li>Key \u2212 The key that will be included in the record.<\/li>\n<li><span style=\"font-weight: 400\">Value \u2212 Record contents.<\/span><\/li>\n<\/ol>\n<p><b>public ProducerRecord (string topic, k key, v value)<\/b><br \/>\n<span style=\"font-weight: 400\">To create a record with the key, value pairs and without partition, we use the ProducerRecord class constructor.<\/span><\/p>\n<ol>\n<li><span style=\"font-weight: 400\"> Topic \u2212 Create a topic to assign record.<\/span><\/li>\n<li><span style=\"font-weight: 400\">Key \u2212 key for the record.<\/span><\/li>\n<li>Value \u2212 Record contents.<\/li>\n<\/ol>\n<p><b>public ProducerRecord (string topic, v value)<\/b><br \/>\n<span style=\"font-weight: 400\">Moreover, without partition and key, ProducerRecord class creates a record.<\/span><\/p>\n<ol>\n<li><span style=\"font-weight: 400\"> Topic \u2212 Create a topic.<\/span><\/li>\n<li>Value \u2212 Record contents.<\/li>\n<\/ol>\n<p><span style=\"font-weight: 400\">Now, here we are listing the ProducerRecord class methods \u2212 <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>1.\u00a0public string topic()<\/strong><\/span><br \/>\nThe topic will append to the record.<\/p>\n<p><strong>2.\u00a0public K key()<\/strong><br \/>\n<span style=\"font-weight: 400\">Key that will be included in the record. If no such key, null will be returned here. <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>3.\u00a0public V value()<\/strong><\/span><br \/>\n<span style=\"font-weight: 400\">To record contents.<\/span><\/p>\n<p><strong>4.\u00a0partition()<\/strong><br \/>\n<span style=\"font-weight: 400\">Partition count for the record.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Simple Kafka Producer Application<\/span><\/h3>\n<p><span style=\"font-weight: 400\">However, make sure that first start<strong> ZooKeeper<\/strong> and Kafka broker then create your own topic in Kafka broker using create topic command. Then create a<strong> Java class<\/strong> named Sim-pleProducer.java and proceed with the following <strong>coding<\/strong>:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">\/\/import util.properties packages\r\nimport java.util.Properties;\r\n\/\/import simple producer packages\r\nimport org.apache.kafka.clients.producer.Producer;\r\n\/\/import KafkaProducer packages\r\nimport org.apache.kafka.clients.producer.KafkaProducer;\r\n\/\/import ProducerRecord packages\r\nimport org.apache.kafka.clients.producer.ProducerRecord;\r\n\/\/Create java class named \u201cSimpleProducer\u201d\r\npublic class SimpleProducer {\r\n  public static void main(String[] args) throws Exception{\r\n     \/\/ Check arguments length value\r\n     if(args.length == 0){\r\n        System.out.println(\"Enter topic name\u201d);\r\n        return;\r\n     }\r\n     \/\/Assign topicName to string variable\r\n     String topicName = args[0].toString();\r\n     \/\/ create instance for properties to access producer configs\r\n     Properties props = new Properties();\r\n     \/\/Assign localhost id\r\n     props.put(\"bootstrap.servers\", \u201clocalhost:9092\");\r\n     \/\/Set acknowledgements for producer requests.\r\n     props.put(\"acks\", \u201call\");\r\n     \/\/If the request fails, the producer can automatically retry,\r\n     props.put(\"retries\", 0);\r\n     \/\/Specify buffer size in config\r\n     props.put(\"batch.size\", 16384);\r\n     \/\/Reduce the no of requests less than 0\r\n     props.put(\"linger.ms\", 1);\r\n     \/\/The buffer.memory controls the total amount of memory available to the producer for buffering.\r\n     props.put(\"buffer.memory\", 33554432);\r\n     props.put(\"key.serializer\",\r\n        \"org.apache.kafka.common.serializa-tion.StringSerializer\");\r\n     props.put(\"value.serializer\",\r\n        \"org.apache.kafka.common.serializa-tion.StringSerializer\");\r\n     Producer&lt;String, String&gt; producer = new KafkaProducer\r\n        &lt;String, String&gt;(props);\r\n     for(int i = 0; i &lt; 10; i++)\r\n        producer.send(new ProducerRecord&lt;String, String&gt;(topicName,\r\n           Integer.toString(i), Integer.toString(i)));\r\n              System.out.println(\u201cMessage sent successfully\u201d);\r\n              producer.close();\r\n  }\r\n}<\/pre>\n<h4>a. Compilation<\/h4>\n<p>By using the following command, we can compile the application.<\/p>\n<pre class=\"EnlighterJSRAW\">\/\/import util.properties packages\r\nimport java.util.Properties;\r\n\/\/import simple producer packages\r\nimport org.apache.kafka.clients.producer.Producer;\r\n\/\/import KafkaProducer packages\r\nimport org.apache.kafka.clients.producer.KafkaProducer;\r\n\/\/import ProducerRecord packages\r\nimport org.apache.kafka.clients.producer.ProducerRecord;\r\n\/\/Create java class named \u201cSimpleProducer\u201d\r\npublic class SimpleProducer {\r\n  public static void main(String[] args) throws Exception{\r\n     \/\/ Check arguments length value\r\n     if(args.length == 0){\r\n        System.out.println(\"Enter topic name\u201d);\r\n        return;\r\n     }\r\n     \/\/Assign topicName to string variable\r\n     String topicName = args[0].toString();\r\n     \/\/ create instance for properties to access producer configs\r\n     Properties props = new Properties();\r\n     \/\/Assign localhost id\r\n     props.put(\"bootstrap.servers\", \u201clocalhost:9092\");\r\n     \/\/Set acknowledgements for producer requests.\r\n     props.put(\"acks\", \u201call\");\r\n     \/\/If the request fails, the producer can automatically retry,\r\n     props.put(\"retries\", 0);\r\n     \/\/Specify buffer size in config\r\n     props.put(\"batch.size\", 16384);\r\n     \/\/Reduce the no of requests less than 0\r\n     props.put(\"linger.ms\", 1);\r\n     \/\/The buffer.memory controls the total amount of memory available to the producer for buffering.\r\n     props.put(\"buffer.memory\", 33554432);\r\n     props.put(\"key.serializer\",\r\n        \"org.apache.kafka.common.serializa-tion.StringSerializer\");\r\n     props.put(\"value.serializer\",\r\n        \"org.apache.kafka.common.serializa-tion.StringSerializer\");\r\n     Producer&lt;String, String&gt; producer = new KafkaProducer\r\n        &lt;String, String&gt;(props);\r\n     for(int i = 0; i &lt; 10; i++)\r\n        producer.send(new ProducerRecord&lt;String, String&gt;(topicName,\r\n           Integer.toString(i), Integer.toString(i)));\r\n              System.out.println(\u201cMessage sent successfully\u201d);\r\n              producer.close();\r\n  }\r\n}<\/pre>\n<h4>b. Execution<\/h4>\n<p><span style=\"font-weight: 400\">Further, using the following command, we can execute the application.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">java -cp \u201c\/path\/to\/kafka\/kafka_2.11-0.9.0.0\/lib\/*\u201d:. SimpleProducer &lt;topic-name&gt;<\/pre>\n<h4>c. Output<\/h4>\n<p><b>Message sent successfully<\/b><br \/>\nTo check the above output open the new terminal and type Consumer CLI command to receive messages.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt; bin\/kafka-console-consumer.sh --zookeeper localhost:2181 \u2014topic &lt;topic-name&gt; \u2014from-beginning<\/pre>\n<p><b>1<\/b><br \/>\n<b>2<\/b><br \/>\n<b>3<\/b><br \/>\n<b>4<\/b><br \/>\n<b>5<\/b><br \/>\n<b>6<\/b><br \/>\n<b>7<\/b><br \/>\n<b>8<\/b><br \/>\n<b>9<\/b><br \/>\n<b>10<\/b><br \/>\nSo, this was all about Apache Kafka Producer. Hope you like our explanation.<\/p>\n<h3><span style=\"font-weight: 400\">Summary: Kafka Producer<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Hence, in this Kafka Tutorial, we have seen the concept of Kafka Producer along with the example. Now, in the next tutorial, we will learn about the <strong>Kafka Consumer<\/strong>, in order to consume messages from the Kafka cluster. Further, we have learned Producer API, Producer class, public void close. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Also, we discussed the configuration setting for the Kafka Producer API and Producer Record API. Finally, we saw SimpleProducer Application with the help of compilation, execution, and output. Furthermore, if you have any doubt, feel free to ask in the comment section.\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our last Kafka Tutorial, we discussed Kafka Cluster. Today, we will discuss Kafka Producer with the example. Moreover, we will see KafkaProducer API and Producer API. Also, we will learn configurations settings in&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":15354,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[825,845,7919,7968,15802],"class_list":["post-14717","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-kafka","tag-apache-kafka","tag-apache-kafka-producer","tag-kafka-producer-api","tag-kafka-tutorial","tag-what-is-kafka-producer"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Apache Kafka Producer For Beginners - DataFlair<\/title>\n<meta name=\"description\" content=\"Apache Kafka Producer,Kafka Producer Example,Kafka Producer API,Producer API,Producer Record API,Simple Producer Application,Producer Class\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/kafka-producer\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apache Kafka Producer For Beginners - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Apache Kafka Producer,Kafka Producer Example,Kafka Producer API,Producer API,Producer Record API,Simple Producer Application,Producer Class\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/kafka-producer\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-04-28T06:45:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-17T13:09:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Apache-Kafka-producer-and-its-example-01-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Apache Kafka Producer For Beginners - DataFlair","description":"Apache Kafka Producer,Kafka Producer Example,Kafka Producer API,Producer API,Producer Record API,Simple Producer Application,Producer Class","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:\/\/data-flair.training\/blogs\/kafka-producer\/","og_locale":"en_US","og_type":"article","og_title":"Apache Kafka Producer For Beginners - DataFlair","og_description":"Apache Kafka Producer,Kafka Producer Example,Kafka Producer API,Producer API,Producer Record API,Simple Producer Application,Producer Class","og_url":"https:\/\/data-flair.training\/blogs\/kafka-producer\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-04-28T06:45:49+00:00","article_modified_time":"2023-08-17T13:09:06+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Apache-Kafka-producer-and-its-example-01-1.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/kafka-producer\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/kafka-producer\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Apache Kafka Producer For Beginners","datePublished":"2018-04-28T06:45:49+00:00","dateModified":"2023-08-17T13:09:06+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/kafka-producer\/"},"wordCount":1113,"commentCount":3,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/kafka-producer\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Apache-Kafka-producer-and-its-example-01-1.jpg","keywords":["Apache Kafka","Apache Kafka Producer","Kafka Producer API","Kafka tutorial","what is kafka producer"],"articleSection":["Apache Kafka Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/kafka-producer\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/kafka-producer\/","url":"https:\/\/data-flair.training\/blogs\/kafka-producer\/","name":"Apache Kafka Producer For Beginners - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/kafka-producer\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/kafka-producer\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Apache-Kafka-producer-and-its-example-01-1.jpg","datePublished":"2018-04-28T06:45:49+00:00","dateModified":"2023-08-17T13:09:06+00:00","description":"Apache Kafka Producer,Kafka Producer Example,Kafka Producer API,Producer API,Producer Record API,Simple Producer Application,Producer Class","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/kafka-producer\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/kafka-producer\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/kafka-producer\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Apache-Kafka-producer-and-its-example-01-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Apache-Kafka-producer-and-its-example-01-1.jpg","width":1200,"height":628,"caption":"Apache Kafka Producer Introduction"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/kafka-producer\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Apache Kafka Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/kafka\/"},{"@type":"ListItem","position":3,"name":"Apache Kafka Producer For Beginners"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/14717","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=14717"}],"version-history":[{"count":3,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/14717\/revisions"}],"predecessor-version":[{"id":118492,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/14717\/revisions\/118492"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/15354"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=14717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=14717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=14717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}