From the course: Apache Kafka Essential Training: Building Scalable Applications
Unlock the full course today
Join today to access over 24,200 courses taught by industry experts.
Producing data in Java - Kafka Tutorial
From the course: Apache Kafka Essential Training: Building Scalable Applications
Producing data in Java
- [Instructor] Let's now look at the use case producer in Java. The code for this chapter is available in the package com.learning.Kafkascalableapps.chapter7. The producer is available in the class use case producer with options.java. Let's review this code now. We first set up the main Kafka producer parameters, namely bootstrap servers, and the key and value serializers. Then we set acknowledgements to all value. To set the batch size to 32K, we use the batch size parameter and provide the number of bytes. Now we proceed to create a Kafka producer. We will publish 10 random messages in a similar fashion, as we did earlier in the course. To publish the record, we create a use case callback class and provide that to the send method. This enables asynchronous publishing. Let's execute this code now. As we can see, we have successfully published 10 messages to Kafka with asynchronous publishing. Let's build a consumer for…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.