Function rd_kafka_commit_transaction

Source
pub unsafe extern "C" fn rd_kafka_commit_transaction(
    rk: *mut rd_kafka_t,
    timeout_ms: c_int,
) -> *mut rd_kafka_error_t
Expand description

Commit the current transaction (as started with rd_kafka_begin_transaction()).

Any outstanding messages will be flushed (delivered) before actually committing the transaction.

If any of the outstanding messages fail permanently the current transaction will enter the abortable error state and this function will return an abortable error, in this case the application must call rd_kafka_abort_transaction() before attempting a new transaction with rd_kafka_begin_transaction().

  • rk: Producer instance.
  • timeout_ms: The maximum time to block. On timeout the operation may continue in the background, depending on state, and it is okay to call this function again. Pass -1 to use the remaining transaction timeout, this is the recommended use.

@remark It is strongly recommended to always pass -1 (remaining transaction time) as the `timeout_ms. Using other values risk internal state desynchronization in case any of the underlying protocol requests fail.

@remark This function will block until all outstanding messages are delivered and the transaction commit request has been successfully handled by the transaction coordinator, or until `timeout_ms expires, which ever comes first. On timeout the application may call the function again.

@remark Will automatically call rd_kafka_flush() to ensure all queued messages are delivered before attempting to commit the transaction. If the application has enabled RD_KAFKA_EVENT_DR it must serve the event queue in a separate thread since rd_kafka_flush() will not serve delivery reports in this mode.

@remark This call is resumable when a retriable timeout error is returned. Calling the function again will resume the operation that is progressing in the background.

Returns NULL on success or an error object on failure. Check whether the returned error object permits retrying by calling rd_kafka_error_is_retriable(), or whether an abortable or fatal error has been raised by calling rd_kafka_error_txn_requires_abort() or rd_kafka_error_is_fatal() respectively. Error codes: RD_KAFKA_RESP_ERR__STATE if not currently in a transaction, RD_KAFKA_RESP_ERR__TIMED_OUT if the transaction could not be complete commmitted within timeout_ms, this is a retriable error as the commit continues in the background, RD_KAFKA_RESP_ERR_INVALID_PRODUCER_EPOCH if the current producer transaction has been fenced by a newer producer instance, RD_KAFKA_RESP_ERR_TRANSACTIONAL_ID_AUTHORIZATION_FAILED if the producer is no longer authorized to perform transactional operations, RD_KAFKA_RESP_ERR__NOT_CONFIGURED if transactions have not been configured for the producer instance, RD_KAFKA_RESP_ERR__INVALID_ARG if rk is not a producer instance, Other error codes not listed here may be returned, depending on broker version.

@remark The returned error object (if not NULL) must be destroyed with rd_kafka_error_destroy().