C AMQP Protocol Engine API  0.7
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Delivery
Collaboration diagram for Delivery:

Modules

 Disposition
 

Classes

struct  pn_delivery_tag_t
 

Typedefs

typedef struct pn_delivery_tag_t pn_delivery_tag_t
 
typedef struct pn_delivery_t pn_delivery_t
 

Functions

PN_EXTERN pn_delivery_tpn_delivery (pn_link_t *link, pn_delivery_tag_t tag)
 
PN_EXTERN void * pn_delivery_get_context (pn_delivery_t *delivery)
 
PN_EXTERN void pn_delivery_set_context (pn_delivery_t *delivery, void *context)
 
PN_EXTERN pn_delivery_tag_t pn_delivery_tag (pn_delivery_t *delivery)
 
PN_EXTERN pn_link_tpn_delivery_link (pn_delivery_t *delivery)
 
PN_EXTERN pn_disposition_tpn_delivery_local (pn_delivery_t *delivery)
 
PN_EXTERN uint64_t pn_delivery_local_state (pn_delivery_t *delivery)
 
PN_EXTERN pn_disposition_tpn_delivery_remote (pn_delivery_t *delivery)
 
PN_EXTERN uint64_t pn_delivery_remote_state (pn_delivery_t *delivery)
 
PN_EXTERN bool pn_delivery_settled (pn_delivery_t *delivery)
 
PN_EXTERN size_t pn_delivery_pending (pn_delivery_t *delivery)
 
PN_EXTERN bool pn_delivery_partial (pn_delivery_t *delivery)
 
PN_EXTERN bool pn_delivery_writable (pn_delivery_t *delivery)
 
PN_EXTERN bool pn_delivery_readable (pn_delivery_t *delivery)
 
PN_EXTERN bool pn_delivery_updated (pn_delivery_t *delivery)
 
PN_EXTERN void pn_delivery_update (pn_delivery_t *delivery, uint64_t state)
 
PN_EXTERN void pn_delivery_clear (pn_delivery_t *delivery)
 
PN_EXTERN void pn_delivery_settle (pn_delivery_t *delivery)
 
PN_EXTERN void pn_delivery_dump (pn_delivery_t *delivery)
 
PN_EXTERN bool pn_delivery_buffered (pn_delivery_t *delivery)
 
PN_EXTERN pn_delivery_tpn_work_head (pn_connection_t *connection)
 
PN_EXTERN pn_delivery_tpn_work_next (pn_delivery_t *delivery)
 

Detailed Description

Typedef Documentation

typedef struct pn_delivery_t pn_delivery_t

An AMQP Delivery object.

A pn_delivery_t object encapsulates all of the endpoint state associated with an AMQP Delivery. Every delivery exists within the context of a pn_link_t object.

The AMQP model for settlement is based on the lifecycle of a delivery at an endpoint. At each end of a link, a delivery is created, it exists for some period of time, and finally it is forgotten, aka settled. Note that because this lifecycle happens independently at both the sender and the receiver, there are actually four events of interest in the combined lifecycle of a given delivery:

  • created at sender
  • created at receiver
  • settled at sender
  • settled at receiver

Because the sender and receiver are operating concurrently, these events can occur in a variety of different orders, and the order of these events impacts the types of failures that may occur when transferring a delivery. Eliminating scenarios where the receiver creates the delivery first, we have the following possible sequences of interest:

Sender presettles (aka at-most-once):

  1. created at sender
  2. settled at sender
  3. created at receiver
  4. settled at receiver

In this configuration the sender settles (i.e. forgets about) the delivery before it even reaches the receiver, and if anything should happen to the delivery in-flight, there is no way to recover, hence the "at most once" semantics.

Receiver settles first (aka at-least-once):

  1. created at sender
  2. created at receiver
  3. settled at receiver
  4. settled at sender

In this configuration the receiver settles the delivery first, and the sender settles once it sees the receiver has settled. Should anything happen to the delivery in-flight, the sender can resend, however the receiver may have already forgotten the delivery and so it could interpret the resend as a new delivery, hence the "at least once" semantics.

Receiver settles second (aka exactly-once):

  1. created at sender
  2. created at receiver
  3. settled at sender
  4. settled at receiver

In this configuration the receiver settles only once it has seen that the sender has settled. This provides the sender the option to retransmit, and the receiver has the option to recognize (and discard) duplicates, allowing for exactly once semantics.

Note that in the last scenario the sender needs some way to know when it is safe to settle. This is where delivery state comes in. In addition to these lifecycle related events surrounding deliveries there is also the notion of a delivery state that can change over the lifetime of a delivery, e.g. it might start out as nothing, transition to PN_RECEIVED and then transition to PN_ACCEPTED. In the first two scenarios the delivery state isn't required, however in final scenario the sender would typically trigger settlement based on seeing the delivery state transition to a terminal state like PN_ACCEPTED or PN_REJECTED.

In practice settlement is controlled by application policy, so there may well be more options here, e.g. a sender might not settle strictly based on what has happened at the receiver, it might also choose to impose some time limit and settle after that period has expired, or it could simply have a sliding window of the last N deliveries and settle the oldest whenever a new one comes along.

An AMQP delivery tag.

Function Documentation

PN_EXTERN pn_delivery_t* pn_delivery ( pn_link_t link,
pn_delivery_tag_t  tag 
)

Create a delivery on a link.

Every delivery object within a link must be supplied with a unique tag. Links maintain a sequence of delivery object in the order that they are created.

Parameters
[in]linka link object
[in]tagthe delivery tag
Returns
a newly created delivery, or NULL if there was an error
PN_EXTERN bool pn_delivery_buffered ( pn_delivery_t delivery)

Check if a delivery is buffered.

A delivery that is buffered has not yet been written to the wire.

Note that returning false does not imply that a delivery was definitely written to the wire. If false is returned, it is not known whether the delivery was actually written to the wire or not.

Parameters
[in]deliverya delivery object
Returns
true if the delivery is buffered
PN_EXTERN void pn_delivery_clear ( pn_delivery_t delivery)

Clear the updated flag for a delivery.

See pn_delivery_updated.

Parameters
[in]deliverya delivery object
PN_EXTERN void pn_delivery_dump ( pn_delivery_t delivery)

Utility function for printing details of a delivery.

Parameters
[in]deliverya delivery object
PN_EXTERN void* pn_delivery_get_context ( pn_delivery_t delivery)

Get the application context that is associated with a delivery object.

The application context for a delivery may be set using pn_delivery_set_context.

Parameters
[in]deliverythe delivery whose context is to be returned.
Returns
the application context for the delivery object
PN_EXTERN pn_link_t* pn_delivery_link ( pn_delivery_t delivery)

Get the parent link for a delivery object.

Parameters
[in]deliverya delivery object
Returns
the parent link
PN_EXTERN pn_disposition_t* pn_delivery_local ( pn_delivery_t delivery)

Get the local disposition for a delivery.

The pointer returned by this object is valid until the delivery is settled.

Parameters
[in]deliverya delivery object
Returns
a pointer to the local disposition
PN_EXTERN uint64_t pn_delivery_local_state ( pn_delivery_t delivery)

Get the local disposition state for a delivery.

Parameters
[in]deliverya delivery object
Returns
the local disposition state
PN_EXTERN bool pn_delivery_partial ( pn_delivery_t delivery)

Check if a delivery only has partial message data.

Parameters
[in]deliverya delivery object
Returns
true if the delivery only contains part of a message, false otherwise
PN_EXTERN size_t pn_delivery_pending ( pn_delivery_t delivery)

Get the amount of pending message data for a delivery.

Parameters
[in]deliverya delivery object
Returns
the amount of pending message data in bytes
PN_EXTERN bool pn_delivery_readable ( pn_delivery_t delivery)

Check if a delivery is readable.

A delivery is considered readable if it is the current delivery on an incoming link.

Parameters
[in]deliverya delivery object
Returns
true if the delivery is readable, false otherwise
PN_EXTERN pn_disposition_t* pn_delivery_remote ( pn_delivery_t delivery)

Get the remote disposition for a delivery.

The pointer returned by this object is valid until the delivery is settled.

Parameters
[in]deliverya delivery object
Returns
a pointer to the remote disposition
PN_EXTERN uint64_t pn_delivery_remote_state ( pn_delivery_t delivery)

Get the remote disposition state for a delivery.

Parameters
[in]deliverya delivery object
Returns
the remote disposition state
PN_EXTERN void pn_delivery_set_context ( pn_delivery_t delivery,
void *  context 
)

Set a new application context for a delivery object.

The application context for a delivery object may be retrieved using pn_delivery_get_context.

Parameters
[in]deliverythe delivery object
[in]contextthe application context
PN_EXTERN void pn_delivery_settle ( pn_delivery_t delivery)

Settle a delivery.

A settled delivery can never be used again.

Parameters
[in]deliverya delivery object
PN_EXTERN bool pn_delivery_settled ( pn_delivery_t delivery)

Check if a delivery is remotely settled.

Parameters
[in]deliverya delivery object
Returns
true if the delivery is settled at the remote endpoint, false otherwise
PN_EXTERN pn_delivery_tag_t pn_delivery_tag ( pn_delivery_t delivery)

Get the tag for a delivery object.

Parameters
[in]deliverya delivery object
Returns
the delivery tag
PN_EXTERN void pn_delivery_update ( pn_delivery_t delivery,
uint64_t  state 
)

Update the disposition of a delivery.

When update is invoked the updated disposition of the delivery will be communicated to the peer.

Parameters
[in]deliverya delivery object
[in]statethe updated delivery state
PN_EXTERN bool pn_delivery_updated ( pn_delivery_t delivery)

Check if a delivery is updated.

A delivery is considered updated whenever the peer communicates a new disposition for the delivery. Once a delivery becomes updated, it will remain so until pn_delivery_clear is called.

Parameters
[in]deliverya delivery object
Returns
true if the delivery is updated, false otherwise
PN_EXTERN bool pn_delivery_writable ( pn_delivery_t delivery)

Check if a delivery is writable.

A delivery is considered writable if it is the current delivery on an outgoing link, and the link has positive credit.

Parameters
[in]deliverya delivery object
Returns
true if the delivery is writable, false otherwise
PN_EXTERN pn_delivery_t* pn_work_head ( pn_connection_t connection)

Extracts the first delivery on the connection that has pending operations.

Retrieves the first delivery on the Connection that has pending operations. A readable delivery indicates message data is waiting to be read. A writable delivery indicates that message data may be sent. An updated delivery indicates that the delivery's disposition has changed. A delivery will never be both readable and writible, but it may be both readable and updated or both writiable and updated.

Parameters
[in]connectionthe connection
Returns
the first delivery object that needs to be serviced, else NULL if none
PN_EXTERN pn_delivery_t* pn_work_next ( pn_delivery_t delivery)

Get the next delivery on the connection that needs has pending operations.

Parameters
[in]deliverythe previous delivery retrieved from either pn_work_head or pn_work_next
Returns
the next delivery that has pending operations, else NULL if none