Interface MessageProducer<K,V>

Type Parameters:
K - key class to send
V - 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 Type
    Method
    Description
    default void
    This method is a blank default implementation in order to avoid it being a breaking change.
    default Future<org.apache.kafka.clients.producer.RecordMetadata>
    send(K key, V value)
    Asynchronously send a record to a specific topic.
    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.
    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.
    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

      default Future<org.apache.kafka.clients.producer.RecordMetadata> send(K key, V value)
      Asynchronously send a record to a specific topic.
      Parameters:
      key - key to send
      value - 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 return null instead of a Future.
    • 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 send
      value - value to send
      headers - 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 return null instead of a Future.
    • 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 send
      value - value to send
      callback - 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 return null instead of a Future.
    • 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 send
      value - value to send
      headers - headers to include in the message
      callback - 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 return null instead of a Future.
    • 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.