From the course: Apache Kafka Essential Training: Getting Started

Unlock this course with a free trial

Join today to access over 25,400 courses taught by industry experts.

Creating a producer in Java

Creating a producer in Java

- [Instructor] Let's explore the Java code for a sample Kafka producer in this video. The code is available in the package com.learning.kafkagettingstarted.chapter5 The class file is KafkaSimpleProducer.java. Let's examine the code now. First, we need to create a properties object to specify the Kafka connection properties. There are three mandatory parameters required. We use the BOOTSTRAP_SERVERS property to specify a list of Kafka brokers. Even if we specify one broker, the kafka client will discover other brokers in the cluster. 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. Since we are accessing kafka from the host system we need to use the external port number, which is 9092. Then we need to specify the key and value serializer classes. These classes are invoked by the kafka client to serialize the message and value to…

Contents