<?xml version="1.0"?>
<!--
  OASIS Advanced Message Queuing Protocol (AMQP) Version 1.0
  Part 4: Transactions

  OASIS Standard
  29 October 2012
    
  Specification URIs:
    
    This version:
        http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transactions-v1.0-os.xml (Authoritative)
        http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transactions-v1.0-os.html
        http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-complete-v1.0-os.pdf
        
    Previous version:
        http://docs.oasis-open.org/amqp/core/v1.0/csprd01/amqp-core-transactions-v1.0-csprd01.xml (Authoritative)
        http://docs.oasis-open.org/amqp/core/v1.0/csprd01/amqp-core-transactions-v1.0-csprd01.html
        http://docs.oasis-open.org/amqp/core/v1.0/csprd01/amqp-core-complete-v1.0-csprd01.pdf

    Latest version:
        http://docs.oasis-open.org/amqp/core/v1.0/amqp-core-transactions-v1.0.xml (Authoritative)
        http://docs.oasis-open.org/amqp/core/v1.0/amqp-core-transactions-v1.0.html
        http://docs.oasis-open.org/amqp/core/v1.0/amqp-core-complete-v1.0.pdf
        
  Technical Committee:
        OASIS Advanced Message Queuing Protocol (AMQP) TC (http://www.oasis-open.org/committees/amqp/)

  Chairs:
        Ram Jeyaraman (Ram.Jeyaraman@microsoft.com), Microsoft
        Angus Telfer (angus.telfer@inetco.com), INETCO Systems

  Editors:
        Robert Godfrey (robert.godfrey@jpmorgan.com), JPMorgan Chase & Co.
        David Ingham (David.Ingham@microsoft.com), Microsoft
        Rafael Schloming (rafaels@redhat.com), Red Hat

  Additional artifacts:
        This specification consists of the following documents:
        Part 0: Overview - Overview of the AMQP specification (amqp-core-overview-v1.0-os.xml)
        Part 1: Types - AMQP type system and encoding (amqp-core-types-v1.0-os.xml)
        Part 2: Transport - AMQP transport layer (amqp-core-transport-v1.0-os.xml)
        Part 3: Messaging - AMQP Messaging Layer (amqp-core-messaging-v1.0-os.xml)
        Part 4: Transactions - AMQP Transactions Layer (this document)
        Part 5: Security - AMQP Security Layers (amqp-core-security-v1.0-os.xml)
        XML Document Type Definition (DTD) (amqp.dtd)

  Related work:
        This specification replaces or supersedes:
            AMQP v1.0 Final, 07 October 2001. http://www.amqp.org/specification/1.0/amqp-org-download
  
  Abstract:

    The Advanced Message Queuing Protocol (AMQP) is an open internet protocol for business
    messaging. It defines a binary wire-level protocol that allows for the reliable exchange
    of business messages between two parties.
    AMQP has a layered architecture and the specification is organized as a set of parts that
    reflects that architecture. Part 1 defines the AMQP type system and encoding. Part 2 defines
    the AMQP transport layer, an efficient, binary, peer-to-peer protocol for transporting messages
    between two processes over a network. Part 3 defines the AMQP message format, with a
    concrete encoding. Part 4 defines how interactions can be grouped within atomic
    transactions. Part 5 defines the AMQP security layers.
    
  Status:
    
    This document was last revised or approved by the membership of OASIS on the above date. The level of
    approval is also listed above. Check the "Latest version" location noted above for possible
    later revisions of this document.

    Technical Committee members should send comments on this specification to the Technical
    Committee's email list. Others should send comments to the Technical Committee by using the
    "Send A Comment" button on the Technical Committee's web page at
    http://www.oasis-open.org/committees/amqp/.

    For information on whether any patents have been disclosed that may be essential to implementing
    this specification, and any offers of patent licensing terms, please refer to the Intellectual
    Property Rights section of the Technical Committee web page
    (http://www.oasis-open.org/committees/amqp/ipr.php).
    
  Citation format:
    
    When referencing this specification the following citation format should be used:
    
    [amqp-core-transactions-v1.0]
    OASIS Advanced Message Queuing Protocol (AMQP) Version 1.0 Part 4: Transactions. 29 October 2012. OASIS Standard.
    http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transactions-v1.0-os.xml
    
  Notices:

  Copyright (c) OASIS Open 2012. All Rights Reserved.


  All capitalized terms in the following text have the meanings assigned to them in the OASIS
  Intellectual Property Rights Policy (the "OASIS IPR Policy"). The full Policy may be found at the
  OASIS website.


  This document and translations of it may be copied and furnished to others, and derivative works
  that comment on or otherwise explain it or assist in its implementation may be prepared, copied,
  published, and distributed, in whole or in part, without restriction of any kind, provided that
  the above copyright notice and this section are included on all such copies and derivative works.
  However, this document itself may not be modified in any way, including by removing the copyright
  notice or references to OASIS, except as needed for the purpose of developing any document or
  deliverable produced by an OASIS Technical Committee (in which case the rules applicable to
  copyrights, as set forth in the OASIS IPR Policy, must be followed) or as required to translate
  it into languages other than English.


  The limited permissions granted above are perpetual and will not be revoked by OASIS or its
  successors or assigns.


  This document and the information contained herein is provided on an "AS IS" basis and OASIS
  DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE
  USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY OWNERSHIP RIGHTS OR ANY IMPLIED WARRANTIES OF
  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.


  OASIS requests that any OASIS Party or any other party that believes it has patent claims that
  would necessarily be infringed by implementations of this OASIS Committee Specification or OASIS
  Standard, to notify OASIS TC Administrator and provide an indication of its willingness to grant
  patent licenses to such patent claims in a manner consistent with the IPR Mode of the OASIS
  Technical Committee that produced this specification.


  OASIS invites any party to contact the OASIS TC Administrator if it is aware of a claim of
  ownership of any patent claims that would necessarily be infringed by implementations of this
  specification by a patent holder that is not willing to provide a license to such patent claims in
  a manner consistent with the IPR Mode of the OASIS Technical Committee that produced this
  specification. OASIS may include such claims on its website, but disclaims any obligation to do
  so.


  OASIS takes no position regarding the validity or scope of any intellectual property or other
  rights that might be claimed to pertain to the implementation or use of the technology described
  in this document or the extent to which any license under such rights might or might not be
  available; neither does it represent that it has made any effort to identify any such rights.
  Information on OASIS' procedures with respect to rights in any document or deliverable produced
  by an OASIS Technical Committee can be found on the OASIS website. Copies of claims of rights
  made available for publication and any assurances of licenses to be made available, or the result
  of an attempt made to obtain a general license or permission for the use of such proprietary
  rights by implementers or users of this OASIS Committee Specification or OASIS Standard, can be
  obtained from the OASIS TC Administrator. OASIS makes no representation that any information or
  list of intellectual property rights will at any time be complete, or that any claims in such list
  are, in fact, Essential Claims.


  The name "OASIS" is a trademark of OASIS, the owner and developer of this specification, and
  should be used only to refer to the organization and its official outputs. OASIS welcomes
  reference to, and implementation and use of, specifications, while reserving the right to enforce
  its marks against misleading uses. Please see http://www.oasis-open.org/policies-guidelines/trademark for above guidance.

     
-->
<amqp name="transactions" label="AMQP Transactions Layer">

  

  <section name="transactions" title="Transactional Messaging">
    <doc>
      <p>
        Transactional messaging allows for the coordinated outcome of otherwise independent
        transfers. This extends to an arbitrary number of transfers spread across any number of
        distinct links in either direction.
      </p>

      <p>
        For every transactional interaction, one container acts as the <i>transactional
        resource</i>, and the other container acts as the <i>transaction controller</i>.
        The <i>transactional resource</i> performs <i>transactional work</i> as requested by
        the <i>transaction controller</i>.
      </p>

      <p>
        The <i>transactional controller</i> and <i>transactional resource</i> communicate over a
        <i>control link</i> which is established by the <i>transactional controller</i>. The <xref name="declare"/> and <xref name="discharge"/> messages are sent by the <i>transactional
        controller</i> over the <i>control link</i> to allocate and complete transactions
        respectively (they do not represent the demarcation of transactional work). No transactional
        work is allowed on the <i>control link</i>. Each transactional operation requested is
        explicitly identified with the desired transaction-id and therefore can occur on any link
        within the controlling session, or, if permitted by the capabilities of the controller, any
        link on the controlling connection. If the <i>control link</i> is closed while there exist
        non-discharged transactions it created, then all such transactions are immediately rolled
        back, and attempts to perform further transactional work on them will lead to failure.
      </p>
    </doc>
  </section>

  <section name="txn-declare" title="Declaring a Transaction">
    <doc>
      <p>
        The container acting as the transactional resource defines a special target that functions
        as a <xref name="coordinator">transaction coordinator</xref>. The <i>transaction
        controller</i> establishes a control link to this target. Note that links to the <xref name="coordinator"/> cannot be resumed.
      </p>
      <p>
        To begin transactional work, the transaction controller needs to obtain a transaction
        identifier from the resource. It does this by sending a message to the <xref name="coordinator"/> whose body consists of the <xref name="declare"/> type in a single
        <xref type="type" name="amqp-value"/> section. Other standard message sections such as the
        header section SHOULD be ignored. This message MUST NOT be sent settled as the sender is
        REQUIRED to receive and interpret the outcome of the declare from the receiver. If the
        coordinator receives a <xref type="type" name="transfer"/> that has been settled by the
        sender, it SHOULD <xref type="type" name="detach"/> with an <xref name="amqp:illegal-state"/> error.
      </p>
      <p>
        If the declaration is successful, the coordinator responds with a disposition outcome of
        <xref name="declared"/> which carries the assigned identifier for the transaction.
      </p>
      <p>
        If the coordinator was unable to perform the <xref name="declare"/> as specified by
        the transaction controller, the transaction coordinator MUST convey the error to the
        controller as a <xref name="transaction-error"/>. If the <xref name="source"/> for the link
        to the <xref name="coordinator"/> supports the <xref name="rejected"/> outcome, then the
        message MUST be <xref name="rejected"/> with this outcome carrying the <xref name="transaction-error"/>. If the <xref name="source"/> does not support the <xref name="rejected"/> outcome, the <i>transactional resource</i> MUST <xref name="detach"/> the
        link to the coordinator, with the <xref name="detach"/> performative carrying the <xref name="transaction-error"/>.
      </p>
      <p>
        Transaction controllers SHOULD establish a control link that allows the
        <xref name="rejected"/> outcome.
      </p>
      <picture title="Declaring a Transaction">
Transaction Controller                  Transactional Resource
===============================================================================

ATTACH(name=txn-ctl,          ---------&gt;
       ...,
       target=
         Coordinator(
           capabilities=
             "amqp:local-transactions")
      )

                             &lt;--------- ATTACH(name=txn-ctl,
                                               ...,
                                               target=
                                                 Coordinator(
                                                   capabilities=
                                                     ["amqp:local-transactions",
                                                      "amqp:multi-txns-per-ssn"]
                                                            )
                                              )

                             &lt;--------- FLOW(...,handle=1, link-credit=1)

TRANSFER(delivery-id=0, ...) ---------&gt;
{ AmqpValue( Declare() ) }

                             &lt;--------- DISPOSITION(first=0, last=0,
                                                    state=Declared(txn-id=0) )

-------------------------------------------------------------------------------

      </picture>
    </doc>
  </section>

  <section name="txn-discharge" title="Discharging a Transaction">
    <doc>
      <p>
        The controller will conclude the transactional work by sending a <xref name="discharge"/>
        message (encoded in a single <xref type="type" name="amqp-value"/> section) to the
        coordinator. The controller indicates that it wishes to commit or rollback the transactional
        work by setting the <i>fail</i> flag on the <xref name="discharge"/> body. As with the <xref type="type" name="declare"/> message, it is an error if the sender sends the <xref type="type" name="transfer"/> pre-settled.
      </p>
      <p>
        If the coordinator is unable to complete the <xref name="discharge"/>, the coordinator
        MUST convey the error to the controller as a <xref name="transaction-error"/>. If the <xref type="type" name="source"/> for the link to the <xref name="coordinator"/> supports the
        <xref type="type" name="rejected"/> outcome, then the message MUST be <xref type="type" name="rejected"/> with this outcome carrying the <xref name="transaction-error"/>. If the
        <xref type="type" name="source"/> does not support the <xref type="type" name="rejected"/>
        outcome, the <i>transactional resource</i> MUST <xref type="type" name="detach"/> the link
        to the coordinator, with the <xref type="type" name="detach"/> performative carrying the
        <xref name="transaction-error"/>. Note that the coordinator MUST always be able to complete
        a <xref name="discharge"/> where the fail flag is set to true (since coordinator failure
        leads to rollback, which is what the controller is asking for).
      </p>

      <picture title="Discharging a Transaction">
Transaction Controller                  Transactional Resource
===============================================================================

TRANSFER(delivery-id=0, ...) ---------&gt;
{ AmqpValue( Declare() ) }

                             &lt;--------- DISPOSITION(first=0, last=0,
                                                    state=Declared(txn-id=0) )

                                  :
                          Transactional Work
                                  :


TRANSFER(delivery-id=57, ...) ---------&gt;
{ AmqpValue(
    Discharge(txn-id=0,
              fail=false)
           ) }

                             &lt;--------- DISPOSITION(first=57, last=57,
                                                    state=Accepted() )

-------------------------------------------------------------------------------

      </picture>
    </doc>
  </section>

  <section name="txn-work" title="Transactional Work">
    <doc>
      <p>
        Transactional work is described in terms of the message states defined in <xref type="section" name="distribution-nodes"/>. Transactional work is formally defined to be
        composed of the following operations:
      </p>

      <ul>
        <li>
          <p><i>posting</i> a message at a target, i.e., making it <i>available</i></p>
        </li>
        <li>
          <p><i>acquiring</i> a message at a source, i.e., transitioning it to <i>acquired</i></p>
        </li>
        <li>
          <p><i>retiring</i> a message at a source, i.e., applying the terminal outcome</p>
        </li>
      </ul>

      <p>
        The transactional resource performs these operations when triggered by the transaction
        controller:
      </p>

      <ul>
        <li>
          <p>
            <i>posting</i> messages is initiated by incoming <xref type="type" name="transfer"/>
            frames
          </p>
        </li>
        <li>
          <p>
            <i>acquiring</i> messages is initiated by incoming <xref type="type" name="flow"/>
            frames
          </p>
        </li>
        <li>
          <p>
            <i>retiring</i> messages is initiated by incoming <xref type="type" name="disposition"/>
            frames
          </p>
        </li>
      </ul>

      <p>
        In each case, it is the responsibility of the transaction controller to identify the
        transaction with which the requested work is to be associated. This is done with the
        transactional delivery state <xref name="transactional-state"/> that combines a txn-id
        together with one of the terminal delivery states defined in <xref type="section" name="delivery-state"/>. The <xref name="transactional-state"/> is carried by both the <xref type="type" name="transfer"/> and the <xref type="type" name="disposition"/> frames allowing
        both the <i>posting</i> and <i>retiring</i> of messages to be associated with a transaction.
      </p>

      <p>
        The <xref type="type" name="transfer"/>, <xref type="type" name="disposition"/>, and <xref type="type" name="flow"/> frames can travel in either direction, i.e., from the controller
        to the resource and from the resource to the controller. When these frames travel from the
        controller to the resource, any embedded txn-ids are requesting that the resource assigns
        transactional work to the indicated transaction. When traveling in the other direction, from
        resource to controller, the <xref type="type" name="transfer"/> and <xref type="type" name="disposition"/> frames indicate work performed, and the txn-ids included MUST correctly
        indicate with which (if any) transaction this work is associated. In the case of the <xref type="type" name="flow"/> frame traveling from resource to controller, the txn-id does not
        indicate work that has been performed, but indicates with which transaction future transfers
        from that link will be performed.
      </p>
    </doc>

    <doc title="Transactional Posting">

      <p>
        If the transaction controller wishes to associate an outgoing <xref name="transfer"/> with a
        transaction, it MUST set the state of the transfer with a <xref name="transactional-state"/>
        carrying the appropriate transaction identifier. Note that if delivery is split across
        several <xref name="transfer"/> frames then all frames MUST be explicitly associated with
        the same transaction. It is an error for the controller to attempt to discharge a
        transaction against which a partial delivery has been posted. If this happens, the
        control link MUST be terminated with the <xref name="transaction-error" choice="transaction-rollback"/> error.
      </p>

      <p>
        The effect of transactional posting is that the message does not become available at the
        destination node within the transactional resource until after the transaction has been
        successfully discharged.
      </p>

      <picture title="Transactional Publish">
Transaction Controller                  Transactional Resource
===============================================================================

TRANSFER(handle=0,           ---------&gt;
         delivery-id=0, ...)
{ AmqpValue( Declare() ) }

                             &lt;--------- DISPOSITION(first=0, last=0,
                                                    state=Declared(txn-id=0) )


TRANSFER(handle=1,           ---------&gt;
         delivery-id=1,
         state=
           TransactionalState(
             txn-id=0) )
{ ... payload ... }

                             &lt;--------- DISPOSITION(first=1, last=1,
                                                    state=TransactionalState(
                                                            txn-id=0,
                                                            outcome=Accepted())
                                                   )

-------------------------------------------------------------------------------

      </picture>

      <p>
        On receiving a non-settled delivery associated with a live transaction, the transactional
        resource MUST inform the controller of the presumptive terminal outcome before it can
        successfully discharge the transaction. That is, the resource MUST send a <xref type="type" name="disposition"/> performative which covers the posted transfer with the state of the
        delivery being a <xref name="transactional-state"/> with the correct transaction identified,
        and a terminal outcome. This informs the controller of the outcome that will be in effect at
        the point that the transaction is successfully discharged.
      </p>
    </doc>

    <doc title="Transactional Retirement">

      <p>
        The transaction controller might wish to associate the outcome of a delivery with a
        transaction. The delivery itself need not be associated with the same transaction as the
        outcome, or indeed with any transaction at all. However, the delivery MUST NOT be associated
        with a different non-discharged transaction than the outcome. If this happens then the
        control link MUST be terminated with a <xref name="transaction-error" choice="transaction-rollback"/> error.
      </p>

      <p>
        To associate an outcome with a transaction the controller sends a <xref type="type" name="disposition"/> performative which sets the state of the delivery to a <xref name="transactional-state"/> with the desired transaction identifier and the outcome to be
        applied upon a successful discharge.
      </p>

      <picture title="Transactional Receive">
Transaction Controller                  Transactional Resource
===============================================================================

TRANSFER(handle=0,           ---------&gt;
         delivery-id=0, ...)
{ AmqpValue( Declare() ) }

                             &lt;--------- DISPOSITION(first=0, last=0,
                                                    state=Declared(txn-id=0) )
FLOW(handle=2,               ---------&gt;
     link-credit=10)

                             &lt;--------- TRANSFER(handle=2,
                                                 delivery-id=11,
                                                 state=null,
                                        { ... payload ... }

                                  :
                                  :

                             &lt;--------- TRANSFER(handle=2,
                                                 delivery-id=20,
                                                 state=null,
                                        { ... payload ... }


DISPOSITION(first=11,        ---------&gt;
            last=20,
            state=TransactionalState(
                    txn-id=0,
                    outcome=Accepted())
           )

-------------------------------------------------------------------------------

      </picture>

      <p>
        On a successful <xref name="discharge"/>, the resource will apply the given outcome and can
        immediately settle the transfers. In the event of a controller-initiated rollback (a <xref name="discharge"/> where the fail flag is set to true) or a resource-initiated rollback (the
        <xref name="discharge"/> message being rejected, or the link to the <xref name="coordinator"/> being detached with an error), the outcome will not be applied, and the
        deliveries will still be "live" and will remain acquired by the controller, i.e., the
        resource can expect the controller to request a disposition for the delivery (either
        transactionally on a new transaction, or non-transactionally).
      </p>
    </doc>

    <doc title="Transactional Acquisition">
      <p>
        In the case of the <xref type="type" name="flow"/> frame, the transactional work is not
        necessarily directly initiated or entirely determined when the <xref type="type" name="flow"/> frame arrives at the resource, but can in fact occur at some later point and
        in ways not necessarily anticipated by the controller. To accommodate this, the resource
        associates an additional piece of state with outgoing link endpoints, a <i>txn-id</i> that
        identifies the transaction with which <i>acquired</i> messages will be associated. This
        state is determined by the controller by specifying a <i>txn-id</i> entry in the
        <i>properties</i> map of the flow frame. When a transaction is discharged, the <i>txn-id</i>
        of any link endpoints will be cleared.
      </p>

      <p>
        If the link endpoint does not support transactional acquisition, the link MUST be terminated
        with a <xref type="type" name="amqp-error" choice="not-implemented"/> error.
      </p>

      <p>
        While the <i>txn-id</i> is cleared when the transaction is discharged, this does
        not affect the level of outstanding credit. To prevent the sending link endpoint from
        acquiring outside of any transaction, the <i>controller</i> SHOULD ensure there is no
        outstanding credit at the sender before it discharges the transaction. The <i>controller</i>
        can do this by either setting the drain mode of the sending link endpoint to <i>true</i>
        before discharging the transaction, or by reducing the <i>link-credit</i> to zero, and
        waiting to hear back that the sender has seen this state change.
      </p>

      <p>
        If a transaction is discharged at a point where a message has been transactionally acquired,
        but has not been fully sent (i.e., the delivery of the message will require more than one
        <xref name="transfer"/> frame and at least one, but not all, such frames have been sent),
        then the resource MUST interpret this to mean that the fate of the acquisition is fully
        decided by the discharge. If the <xref name="discharge"/> indicates the failure of the
        transaction the resource MUST abort or complete sending the remainder of the message before
        completing the discharge.
      </p>

      <picture title="Transactional Acquisition">
Transaction Controller                  Transactional Resource
===============================================================================

TRANSFER(handle=0,           ---------&gt;
         delivery-id=0, ...)
{ AmqpValue( Declare() ) }

                             &lt;--------- DISPOSITION(first=0, last=0,
                                                    state=Declared(txn-id=0) )
FLOW(handle=2,               ---------&gt;
     link-credit=10,
     drain=true,
     properties={
       txn-id=0
     })

                             &lt;--------- TRANSFER(handle=2,
                                                 delivery-id=11,
                                                 state=
                                                   TransactionalState(txn-id=0),
                                        { ... payload ... }

                                  :
                                  :

                             &lt;--------- TRANSFER(handle=2,
                                                 delivery-id=20,
                                                 state=
                                                   TransactionalState(txn-id=0),
                                        { ... payload ... }


DISPOSITION(first=11,        ---------&gt;
            last=20,
            state=TransactionalState(
                    txn-id=0,
                    outcome=Accepted())
           )

-------------------------------------------------------------------------------

      </picture>

    </doc>

    <doc title="Interaction of Settlement with Transactions">
      <p>
        The transport layer defines a notion of <i>settlement</i> which refers to the point at which
        the association of a delivery-tag to a delivery attempt is forgotten. Transactions do not in
        themselves change this notion, however the fact that transactional work can be rolled back
        does have implications for deliveries which the endpoint has marked as settled (and for
        which it can therefore no longer exchange state information using the previously allocated
        transport level identifiers).
      </p>

      <doc title="Transactional Posting">
        <dl>
          <dt>Delivery Sent Settled By Controller</dt>
          <dd><p>The delivered message will not be made available at the node until the transaction
              has been successfully discharged. If the transaction is rolled back then the delivery
              is not made available. If the resource is unable to process the delivery it MUST
              NOT allow the successful discharge of the associated transaction. This can be
              communicated by immediately destroying the controlling link on which the transaction
              was declared, or by rejecting any attempt to discharge the transaction where the fail
              flag is not set to true.
            </p>
          </dd>
          <dt>Delivery Sent Unsettled By Controller; Resource Settles</dt>
          <dd><p>The resource MUST determine the outcome of the delivery before committing the
              transaction, and this MUST be communicated to the controller before the acceptance of
              a successful discharge. The outcome communicated by the resource MUST be associated
              with the same transaction with which the <xref name="transfer"/> from controller to
              resource was associated.
            </p>
            <p>
              If the transaction is rolled back then the delivery is not made available at the
              target. If the resource can no longer apply the outcome that it originally indicated
              would be the result of a successful discharge then it MUST NOT allow the successful
              discharge of the associated transaction. This can be communicated by immediately
              destroying the controlling link on which the transaction was declared, or by rejecting
              any attempt to discharge the transaction where the fail flag is not set to true.
            </p>
          </dd>
          <dt>Delivery Sent Unsettled By Controller; Resource Does Not Settle</dt>
          <dd><p>Behavior prior to discharge is the same as the previous case.</p>
            <p>
              After a successful discharge, the state of unsettled deliveries at the resource MUST
              reflect the outcome that was applied. If the discharge was unsuccessful then an
              outcome SHOULD NOT be associated with the unsettled deliveries. The controller SHOULD
              settle any outstanding unsettled deliveries in a timely fashion after the transaction
              has discharged.
            </p>
          </dd>
        </dl>
      </doc>
      <doc title="Transactional Retirement">
        <p>
          This section considers the cases where the resource has sent messages to the controller in
          a non-transactional fashion. For the cases where the resource sends the messages
          transactionally, see <xref type="doc" name="transactional-acquisition"/>.
        </p>
        <dl>
          <dt>Delivery Sent Unsettled By Resource; Controller Settles</dt>
          <dd><p>Upon a successful discharge the outcome specified by the controller is applied at
              the source. If the controller requests a rollback or the discharge attempt be
              unsuccessful, then the outcome is not applied. At this point the controller can no
              longer influence the state of the delivery as it is settled, and the resource MUST
              apply the default outcome.
            </p>
          </dd>
          <dt>Delivery Sent Unsettled By Resource; Controller Does Not Settle</dt>
          <dd><p>The resource might or might not settle the delivery before the transaction is
              discharged. If the resource settles the delivery before the discharge then the
              behavior after discharge is the same as the case above.
            </p>
            <p>
              Upon a successful discharge the outcome is applied. Otherwise the state reverts to
              that which occurred before the controller sent its (transactional) disposition. The
              controller is free to update the state using subsequent transactional or
              non-transactional updates.
            </p>
          </dd>
        </dl>
      </doc>
      <doc name="transactional-acquisition" title="Transactional Acquisition">
        <dl>
          <dt>Delivery Sent Settled By Resource</dt>
          <dd><p>In the event of a successful discharge the outcome applies at the resource,
              otherwise the acquisition and outcome are rolled back.
            </p>
          </dd>
          <dt>Delivery Sent Unsettled By Resource; Controller Sends Outcome</dt>
          <dd><p>An outcome sent by the controller before the transaction has discharged MUST
              be associated with the same transaction. In the even of a successful discharge the
              outcome is applied at the source, otherwise both the acquisition and outcome are
              rolled back.
            </p>
          </dd>
        </dl>
      </doc>
    </doc>
  </section>

  <section name="coordination" label="types used to interact with a coordinator node">
    <type class="composite" name="coordinator" source="list" provides="target" label="target for communicating with a transaction coordinator">
      <doc>
        <p>
          The coordinator type defines a special target used for establishing a link with a
          transaction coordinator.
        </p>
      </doc>

      <descriptor name="amqp:coordinator:list" code="0x00000000:0x00000030"/>

      <field name="capabilities" type="symbol" requires="txn-capability" multiple="true" label="the capabilities supported at the coordinator">
        <doc>
          <p>
            When sent by the transaction controller (the sending endpoint), indicates the desired
            capabilities of the coordinator. When sent by the resource (the receiving endpoint),
            defined the actual capabilities of the coordinator. Note that it is the responsibility
            of the transaction controller to verify that the capabilities of the controller meet its
            requirements. See <xref name="txn-capability"/>.
        </p>
        </doc>
      </field>

    </type>

    <type class="composite" name="declare" source="list" label="message body for declaring a transaction id">
      <doc>
        <p>
          The declare type defines the message body sent to the coordinator to declare a
          transaction. The txn-id allocated for this transaction is chosen by the transaction
          controller and identified in the <xref name="declared"/> resulting outcome.
        </p>
      </doc>

      <descriptor name="amqp:declare:list" code="0x00000000:0x00000031"/>

      <field name="global-id" type="*" requires="global-tx-id" label="global transaction id">
        <doc>
          <p>
            Specifies that the txn-id allocated by this declare MUST be associated with the
            indicated global transaction. If not set, the allocated txn-id will be associated with a
            local transaction. This field MUST NOT be set if the coordinator does not have the <xref name="txn-capability" choice="distributed-transactions"/> capability. Note that the
            details of distributed transactions within AMQP 1.0 will be provided in a separate
            specification.
          </p>
        </doc>
      </field>
    </type>

    <type class="composite" name="discharge" source="list" label="message body for discharging a transaction">
      <doc>
        <p>
          The discharge type defines the message body sent to the coordinator to indicate that the
          txn-id is no longer in use. If the transaction is not associated with a global-id, then
          this also indicates the disposition of the local transaction.
        </p>
      </doc>

      <descriptor name="amqp:discharge:list" code="0x00000000:0x00000032"/>

      <field name="txn-id" type="*" requires="txn-id" mandatory="true" label="identifies the transaction to be discharged"/>

      <field name="fail" type="boolean" label="indicates the transaction has failed">
        <doc>
          <p>
            If set, this flag indicates that the work associated with this transaction has failed,
            and the controller wishes the transaction to be rolled back. If the transaction is
            associated with a global-id this will render the global transaction rollback-only. If
            the transaction is a local transaction, then this flag controls whether the transaction
            is committed or aborted when it is discharged. (Note that the specification for
            distributed transactions within AMQP 1.0 will be provided separately in Part 6
            Distributed Transactions).
          </p>
        </doc>
      </field>
    </type>

    <type class="restricted" name="transaction-id" source="binary" provides="txn-id">
      <doc>
        <p>
          A transaction-id can be up to 32 octets of binary data.
        </p>
      </doc>
    </type>

    <type class="composite" name="declared" source="list" provides="delivery-state, outcome">
      <doc>
        <p>
          Indicates that a transaction identifier has successfully been allocated in response to a
          declare message sent to a transaction coordinator.
        </p>
      </doc>

      <descriptor name="amqp:declared:list" code="0x00000000:0x00000033"/>

      <field name="txn-id" type="*" requires="txn-id" mandatory="true" label="the allocated transaction id"/>
    </type>

    <type class="composite" name="transactional-state" provides="delivery-state" source="list" label="the state of a transactional message transfer">
      <doc>
        <p>
          The transactional-state type defines a delivery-state that is used to associate a delivery
          with a transaction as well as to indicate which outcome is to be applied if the
          transaction commits.
        </p>
      </doc>

      <descriptor name="amqp:transactional-state:list" code="0x00000000:0x00000034"/>

      <field name="txn-id" type="*" mandatory="true" requires="txn-id" label="identifies the transaction with which the state is associated"/>
      <field name="outcome" type="*" requires="outcome" label="provisional outcome">
        <doc>
          <p>
            This field indicates the provisional outcome to be applied if the transaction commits.
          </p>
        </doc>
      </field>
    </type>

    <type class="restricted" name="txn-capability" source="symbol" provides="txn-capability" label="symbols indicating (desired/available) capabilities of a transaction coordinator">

      <choice name="local-transactions" value="amqp:local-transactions">
        <doc>
          <p>
              Support local transactions.
          </p>
        </doc>
      </choice>

      <choice name="distributed-transactions" value="amqp:distributed-transactions">
        <doc>
          <p>
              Support AMQP Distributed Transactions.
          </p>
        </doc>
      </choice>

      <choice name="promotable-transactions" value="amqp:promotable-transactions">
        <doc>
          <p>
              Support AMQP Promotable Transactions.
          </p>
        </doc>
      </choice>

      <choice name="multi-txns-per-ssn" value="amqp:multi-txns-per-ssn">
        <doc>
          <p>
              Support multiple active transactions on a single session.
          </p>
        </doc>
      </choice>

      <choice name="multi-ssns-per-txn" value="amqp:multi-ssns-per-txn">
        <doc>
          <p>
              Support transactions whose txn-id is used across sessions on one connection.
          </p>
        </doc>
      </choice>
    </type>

    <type class="restricted" name="transaction-error" source="symbol" provides="error-condition" label="symbols used to indicate transaction errors">
      <choice name="unknown-id" value="amqp:transaction:unknown-id">
        <doc>
          <p>The specified txn-id does not exist.</p>
        </doc>
      </choice>

      <choice name="transaction-rollback" value="amqp:transaction:rollback">
        <doc>
          <p>The transaction was rolled back for an unspecified reason.</p>
        </doc>
      </choice>

      <choice name="transaction-timeout" value="amqp:transaction:timeout">
        <doc>
          <p>The work represented by this transaction took too long.</p>
        </doc>
      </choice>
    </type>
  </section>

</amqp>
