Member-only story

Kafka Producer Example Using Java

Gain Java Knowledge
4 min readSep 25, 2020

--

In this article, we will see how to produce records/messages with Kafka brokers. Let’s get to it!

In last article, we discussed how to install Apache Kafka using Zookeeper on windows. In this article, we will see how to produce records/messages with Kafka brokers.

Now, before creating a Kafka producer in java, we need to define the essential Project dependencies. In our project, there will be three dependencies required:

Open start.spring.io and Create Maven Project with these three dependencies. Lombok is used to generate setter/getter methods.

So After Generating the project we will extract this. We will import this project into Eclipse.

Here In this project we will create one Rest Endpoint that will be used to publish the message on topic.

So, First we will create KafkaProducerConfig.java class in package com.example.kafkaproducer.config. Here we will define KafkaProducer with some properties.

--

--

Gain Java Knowledge
Gain Java Knowledge

Written by Gain Java Knowledge

The Java programming language is one of the most popular languages today. Stay up to date with news, certifications, free learning resources and much more.

No responses yet