How to create kafka producer API

0 votes

Hi everyone,

Can somebody tell me how to create kafka producer API?

Thank You

Feb 11, 2020 in Apache Kafka by akhtar
• 38,260 points
915 views

1 answer to this question.

0 votes

Hi@akhtar,

To create kafka producer API, you can use the below code and change your key/value pair according to your need.

import java.util.*;
import org.apache.kafka.clients.producer.*;
public class ProducerAPI {
   public static void main(String[] args) throws Exception{   
      String topicName = "ProducerAPI";
  String key = "Key1";
  String value = "Value-1";
      Properties props = new Properties();
      props.put("bootstrap.servers", "localhost:9092,localhost:9093");
      props.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer");         
      props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");     
      Producer<String, String> producer = new KafkaProducer <>(props);
  ProducerRecord<String, String> record = new ProducerRecord<>(topicName,key,value);
  producer.send(record);        
      producer.close();
  System.out.println("ProducerAPI Completed.");
}
}

Thank You

answered Feb 11, 2020 by MD
• 95,460 points

Related Questions In Apache Kafka

0 votes
1 answer

How to create a Kafka producer?

Hi@MD, Generally, Kafka producer comes from an API. ...READ MORE

answered Dec 7, 2020 in Apache Kafka by akhtar
• 38,260 points
822 views
0 votes
1 answer

How to write Kafka connector to integrate with Facebook API?

If you know the limit of API ...READ MORE

answered Apr 29, 2019 in Apache Kafka by Kumar
2,824 views
0 votes
1 answer

How to create a Kafka topic in a broker?

Hi@akhtar, To create a Kafka topic, you need ...READ MORE

answered Dec 7, 2020 in Apache Kafka by MD
• 95,460 points
1,634 views
0 votes
1 answer

How to reset the offset of messages consumed from Kafka?

The reset option only prints the result ...READ MORE

answered Jul 10, 2018 in Apache Kafka by Shubham
• 13,490 points
14,048 views
0 votes
1 answer

What is the need of serializer in Kafka Producer API?

Hi@akhtar, If we try to use String key ...READ MORE

answered Feb 11, 2020 in Apache Kafka by MD
• 95,460 points
1,284 views
0 votes
1 answer

What is the use of acts configuration in Kafka Producer API?

Hi@akhtar, The acts configuration is used to configure ...READ MORE

answered Feb 11, 2020 in Apache Kafka by MD
• 95,460 points
1,488 views
0 votes
1 answer

What is the meaning of retries in Kafka Producer API?

Hi@akhtar, It defines how many time the producer ...READ MORE

answered Feb 11, 2020 in Apache Kafka by MD
• 95,460 points
4,432 views
+2 votes
9 answers

Writing the Kafka consumer output to a file

System.out.println(String.valueOf(output.offset()) + ": " + new String(bytes, ...READ MORE

answered Dec 7, 2018 in Apache Kafka by Harsh
38,719 views
0 votes
1 answer

How to create Kafka consumer API?

Hi@akhtar, If you know the kafka producer API ...READ MORE

answered Feb 11, 2020 in Apache Kafka by MD
• 95,460 points
1,560 views
0 votes
1 answer

How can i connect to an api which gives me weather data to Apache kafka?

Hi, To connect an API in kafka, you ...READ MORE

answered Apr 13, 2020 in Apache Kafka by MD
• 95,460 points
1,359 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP