Kafka

Simple Producer Example

Simple Producer Example

Kafka Producer is responsible for writing and publishing data on a certain topic within partitions. It does so using two ways - Message Keys and Acknowledgement. 

 

KafkaProducer API uses the following signature to send and share messages asynchronously. 

producer.send(new ProducerRecord<byte[],byte[]>(topic, 

partition, key1, value1) , callback);

 

The Flush Method helps confirm with the KafkaProducer that all the previous message requests have been completed. Here is the syntax for Flush Method -

 

public void flush()

 

The partitionFor method helps in custom partitioning of metadata for a given topic. Here is the syntax for this method -

 

public Map metrics()