From the course: Apache Kafka Essential Training: Getting Started (2021)

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Creating a producer in Java

Creating a producer in Java

From the course: Apache Kafka Essential Training: Getting Started (2021)

Start my 1-month free trial

Creating a producer in Java

- [Instructor] Let's explore the Java code for a simple KafkaProducer in this video. The code is available in the package, com.learning.kafkagettingstarted.chapter5. The classified list, KafkaSimpleProducer.Java. Let's explore the code now. To connect to Kafka, we need to create a properties object to specify the Kafka connection properties. There are three mandatory parameters required here. First, we need to use the bootstrap server property to specify a list of Kafka brokers. Even if we specify one broker, the Kafka client will discover other brokers in the system. It is, however, recommended to specify at least two so even if the first broker is out of service the second one can be used for discovery. Then, we need to specify the key and value serializer_classes. These classes are invoked by Kafka client to serialize the message and value into bytes. In this case, we are specifying a string serializer as both these…

Contents