Deep-Dive into Spring Boot Kafka Components
In the previous chapter, we did a quick start with Kafka in Spring Boot. In this chapter, we are going to deep-dive into each of its components and offerings to understand if we can use it to implement our own use case. To connect with Kafka, we need to focus primarily on the following beans provided by Kafka:
KafkaAdmin
- To configure topics in Kafka programmaticallyProducerFactory
- To define or override configurations for producing messages to KafkaConsumerFactory
- To define or override configurations for consuming messages from Kafka
Now, before we start looking into each of the components, we are going to revisit Steve and Jane's e-commerce app that we discussed in our previous chapters and select a basic microservice that we can use for implementation.
Since we will be focusing on a simple pub-sub module, let's choose the Inventory Service where we will publish new items added to the inventory list into the Kafka topic and then consume it to update or forward that information to other services or topics.
Configuration of Kafka Topics
Let's begin with our first component as part of Kafka in Spring Boot. Until now, if you have noticed, we have used command-line tools to create topics in Kafka. For example, in the previous chapter, we ran something like this: