Apache kafka Producer
In the publish and subscribe messaging system, the flow starts from the Publisher(which sends a piece of message to the broker(Kafka)).
Kafka comes with Client API , which can interm help to communicate with Kafka. The following is the example for the Kafka Producer, which will help you to understand how we are communicating with Kafka while sending the message(Record).
In the above example, we are creating four properties to the Properties Class. The following is the description and use cases of those four properties.
bootstrap.servers helps to provide the Kafka broker details list, we can pass the list of brokers as well with "," separated.
We can pass as many brokers as we want based on the load. For now just dont go indepth about how the multiple brokers works later chapters we can see those.
client.id Can be anything which will be helpful to identify from which Client we sent the message to the Kafka.
By default kafka expects both key and value as a byte array but we can pass the custom class as well.But the custom class should have some specific behavior(Later chapters we can learn). key.serializer value should be the name of the class which is used for serializing the Key. For the example we have used default implementation from the Kafka Client API.
value.serializer value should be the name of the class which is used for serializing the Key, or the example we have used default implementation from the Kafka Client API.