...

Big Data - Apache Kafka

Back to Course

Lesson Description


Lession - #455 Kafka Producer API


The Kafka Producer API allows applications to send streams of data to the Kafka cluster.

The Kafka Consumer API permits applications to read surges of data from the cluster.

Producer API

Allow us to get the main arrangement of Kafka maker API in this part. The focal piece of the KafkaProducer API is KafkaProducer class. The KafkaProducer class gives a choice to interface a Kafka intermediary in its constructor with the accompanying strategies.

KafkaProducer class gives send technique to send messages nonconcurrently to a point. The mark of send(>
is as per the following


producer.send(new ProducerRecord(topic,
segment, key1, value1>
, callback>
;'
ProducerRecord − The producer deals with a support of records ready to be sent.

Callback − A client provided callback to execute when the record has been acknowl-edged by the server (invalid shows no callback>
.

KafkaProducer class gives a flush technique to guarantee all recently sent messages have been really finished. Punctuation of the flush strategy is as per the following −

public void flush(>

KafkaProducer class gives partitionFor technique, which helps in getting the segment metadata for a given subject. This can be utilized for custom dividing. The mark of this strategy is as per the following −

public Map measurements(>

It returns the guide of inward measurements kept up with by the maker.

public void close(>
− KafkaProducer class gives close technique blocks until all recently sent demands are finished.

Producer API

The focal piece of the Producer API is Producer class. Maker class gives a choice to associate Kafka merchant in its constructor by the accompanying strategies.

The Producer example of Class

The maker class gives send technique to send messages to one or the other single or various points utilizing the accompanying marks.


public void send(KeyedMessaget<k,v> message>


- sends the information to a single topic,par-titioned by key utilizing either sync or async producer.


public void send(List `>messages>
- sends information to numerous topics.


Properties prop = new Properties(>
; prop.put(producer.type,"async">
ProducerConfig config = new ProducerConfig(prop>
;


What is a Kafka sink connector?
The Kafka Connect JDBC Sink connector allows you to export data from Apache Kafka® topics to any relational database with a JDBC driver.

What is Kafka REST API?
The Kafka REST Proxy is a RESTful web API that allows your application to send and receive messages using HTTP rather than TCP. Kafka vs spark
Kafka has Producer, Consumer, Topic to work with data. Where Spark provides platform pull the data, hold it, process and push from source to target.