Kafka Producer APIs
Kafka has provided you with a rich set of APIs to create applications to interact with it. We will go through Producer API details and understand its uses.
Creating a Kafka producer involves the following steps:
- Required configuration.
- Creating a producer object.
- Setting up a producer record.
- Creating a custom partition if required.
- Additional configuration.
Required configuration: In most applications, we first start with creating the initial configuration without which we cannot run the application. The following are three mandatory configuration parameters:
bootstrap.servers
: This contains a list of Kafka brokers addresses. The address is specified in terms ofhostname:port
. We can specify one or more broker detail, but we recommend that you provide at least two so that if one broker goes down, producer can use the other one.
Note
It is not necessary to specify all brokers as the Kafka producer queries this configured broker for information about other brokers. In older versions...