Interface MessageProducer<K,V>
- Type Parameters:
K
- key class to sendV
- value class to send
- All Known Implementing Classes:
KafkaMessageProducer
public interface MessageProducer<K,V>
A Kafka client that publishes records to the Kafka cluster for a specific topic.
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
flush()
This method is a blank default implementation in order to avoid it being a breaking change.default Future<org.apache.kafka.clients.producer.RecordMetadata>
Asynchronously send a record to a specific topic.default Future<org.apache.kafka.clients.producer.RecordMetadata>
Asynchronously send a record to a specific topic and invoke the provided callback when the sending has been acknowledged.default Future<org.apache.kafka.clients.producer.RecordMetadata>
Asynchronously send a record to a specific topic.Future<org.apache.kafka.clients.producer.RecordMetadata>
send
(K key, V value, org.apache.kafka.common.header.Headers headers, org.apache.kafka.clients.producer.Callback callback) Asynchronously send a record to a specific topic and invoke the provided callback when the sending has been acknowledged.
-
Method Details
-
send
Asynchronously send a record to a specific topic.- Parameters:
key
- key to sendvalue
- value to send- Returns:
- The result of sending is a
RecordMetadata
specifying the partition the record was sent to, the offset it was assigned and the timestamp of the record. Noop implementations may returnnull
instead of aFuture
.
-
send
default Future<org.apache.kafka.clients.producer.RecordMetadata> send(K key, V value, org.apache.kafka.common.header.Headers headers) Asynchronously send a record to a specific topic.- Parameters:
key
- key to sendvalue
- value to sendheaders
- headers to include in the message- Returns:
- The result of sending is a
RecordMetadata
specifying the partition the record was sent to, the offset it was assigned and the timestamp of the record. Noop implementations may returnnull
instead of aFuture
.
-
send
default Future<org.apache.kafka.clients.producer.RecordMetadata> send(K key, V value, org.apache.kafka.clients.producer.Callback callback) Asynchronously send a record to a specific topic and invoke the provided callback when the sending has been acknowledged. The sending is asynchronous and this method will return immediately once the record has been stored in the buffer of records waiting to be sent.- Parameters:
key
- key to sendvalue
- value to sendcallback
- callback to invoke- Returns:
- The result of sending is a
RecordMetadata
specifying the partition the record was sent to, the offset it was assigned and the timestamp of the record. Noop implementations may returnnull
instead of aFuture
.
-
send
Future<org.apache.kafka.clients.producer.RecordMetadata> send(K key, V value, org.apache.kafka.common.header.Headers headers, org.apache.kafka.clients.producer.Callback callback) Asynchronously send a record to a specific topic and invoke the provided callback when the sending has been acknowledged. The sending is asynchronous and this method will return immediately once the record has been stored in the buffer of records waiting to be sent.- Parameters:
key
- key to sendvalue
- value to sendheaders
- headers to include in the messagecallback
- callback to invoke- Returns:
- The result of sending is a
RecordMetadata
specifying the partition the record was sent to, the offset it was assigned and the timestamp of the record. Noop implementations may returnnull
instead of aFuture
.
-
flush
default void flush()This method is a blank default implementation in order to avoid it being a breaking change. The implementing class must override this to add behaviour to it. The implementation should call the flush() method of the producer.
-