Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleCallback.java
public interface Callback {

   	@Deprecated
    void onCompletion(RecordMetadata metadata, Exception exception);

	class SendFailure {
        FailureType failureType;
        Exception cause;
    }

    enum FailureType {
        MESSSAGE_REJECTED, // the specific record being produced was rejected, such as InvalidTopic or RecordTooLarge
		DELIVERY_FAILED, // a failure to produce last record, such as NotEnoughReplicas or Timeout
		TRANSACTION_FAILED // a transactional processing failure, such as ProducerFenced or InvalidTransactionState
    }

	/**
     * A callback method the user can implement to provide asynchronous handling of request completion. This method will
     * be called when the record sent to the server has been acknowledged. When exception is not null in the callback,
     * metadata will contain the special -1 value for all fields except for topicPartition, which will be valid.
     *
     * @param metadata    The metadata for the record that was sent (i.e. the partition and offset). An empty metadata
     *                    with -1 value for all fields except for topicPartition will be returned if an error occurred.
     * @param sendFailure The struct containing the failure type and exception cause.
     */
    default void onCompletion(RecordMetadata metadata, SendFailure sendFailure) {
        this.onCompletion(metadata, sendFailure.cause);
    }
}

...