Module : transactions

Module overview

This module provides Ballerina transaction manager implementation.

The code snippet given below uses the functions in the module to get the transaction information.


// When the `transaction` statement starts, a distributed transaction context is created.
transaction {
    // Print the current transaction ID
    log:printInfo("Started transaction: " +
                     transactions:getCurrentTransactionId());

    // When a participant is called, the transaction context is propagated, and that participant
    // gets infected and joins the distributed transaction.
    boolean successful = callBusinessService();
    if (successful) {
        log:printInfo("Business operation executed successfully");
    } else {
        log:printError("Business operation failed");
        abort;
    }

    // As soon as the `transaction` block ends, the `2-phase commit
    // coordination` protocol will run. All participants are prepared
    // and depending on the joint outcome, either a `notify commit` or
    // `notify abort` will be sent to the participants.
} committed {
    log:printInfo("Initiated transaction committed");
} aborted {
    log:printInfo("Initiated transaction aborted");
}

Records

NotifyRequest
NotifyResponse
Participant2pcClientConfig
ParticipantFunctionResult
PrepareRequest
PrepareResponse
RemoteProtocol This represents the protocol associated with the coordination type.
RequestError
TransactionContext
TransactionParticipantConfig Contains the configurations for local transaction participant function.

Clients

Participant2pcClientEP

Functions

getCurrentTransactionId

Get the current transaction id. This function is useful for user code to save state against a transaction ID, so that when the oncommit or onabort functions registered for a transaction can retrieve that state using the transaction that is passed in to those functions.

registerParticipantWithRemoteInitiator

Registers a participant with the initiator's coordinator. This function will be called by the participant.

Constants

COMMAND_PREPARE
COMMAND_COMMIT
COMMAND_ABORT
PREPARE_RESULT_PREPARED_STR
PREPARE_RESULT_ABORTED_STR
PREPARE_RESULT_COMMITTED_STR
PREPARE_RESULT_READ_ONLY_STR
NOTIFY_RESULT_NOT_PREPARED_STR
NOTIFY_RESULT_FAILED_EOT_STR
NOTIFY_RESULT_COMMITTED_STR
NOTIFY_RESULT_ABORTED_STR
OUTCOME_COMMITTED
OUTCOME_ABORTED
TRANSACTION_UNKNOWN

Annotations

Participant

The annotation which is used to configure local transaction participant function.

Types

UProtocol