| 1 |
.. _overview: |
| 2 |
|
| 3 |
############ |
| 4 |
API Overview |
| 5 |
############ |
| 6 |
|
| 7 |
========================= |
| 8 |
An overview of the model |
| 9 |
========================= |
| 10 |
|
| 11 |
Messages are transferred between connected peers over 'links'. At the |
| 12 |
sending peer the link is called a sender. At the receiving peer it is |
| 13 |
called a receiver. Messages are sent by senders and received by |
| 14 |
receivers. Links may have named 'source' and 'target' addresses (for |
| 15 |
example to identify the queue from which message were to be received |
| 16 |
or to which they were to be sent). |
| 17 |
|
| 18 |
Links are established over sessions. Sessions are established over |
| 19 |
connections. Connections are (generally) established between two |
| 20 |
uniquely identified containers. Though a connection can have multiple |
| 21 |
sessions, often this is not needed. The container API allows you to |
| 22 |
ignore sessions unless you actually require them. |
| 23 |
|
| 24 |
The sending of a message over a link is called a delivery. The message |
| 25 |
is the content sent, including all meta-data such as headers and |
| 26 |
annotations. The delivery is the protocol exchange associated with the |
| 27 |
transfer of that content. |
| 28 |
|
| 29 |
To indicate that a delivery is complete, either the sender or the |
| 30 |
receiver 'settles' it. When the other side learns that it has been |
| 31 |
settled, they will no longer communicate about that delivery. The |
| 32 |
receiver can also indicate whether they accept or reject the |
| 33 |
message. |
| 34 |
|
| 35 |
Three different delivery levels or 'guarantees' can be achieved: |
| 36 |
at-most-once, at-least-once or exactly-once. See |
| 37 |
:ref:`delivery-guarantees` for more detail. |
| 38 |
|
| 39 |
======================================================= |
| 40 |
A summary of the most commonly used classes and members |
| 41 |
======================================================= |
| 42 |
|
| 43 |
A brief summary of some of the key classes follows. |
| 44 |
|
| 45 |
The :py:class:`~proton.reactor.Container` class is a convenient entry |
| 46 |
point into the API, allowing connections and links to be |
| 47 |
established. Applications are structured as one or more event |
| 48 |
handlers. Handlers can be set at Container, Connection, or Link |
| 49 |
scope. Messages are sent by establishing an appropriate sender and |
| 50 |
invoking its :py:meth:`~proton.Sender.send()` method. This is |
| 51 |
typically done when the sender is sendable, a condition indicated by |
| 52 |
the :py:meth:`~proton.handlers.MessagingHandler.on_sendable()` event, to |
| 53 |
avoid excessive build up of messages. Messages can be received by |
| 54 |
establishing an appropriate receiver and handling the |
| 55 |
:py:meth:`~proton.handlers.MessagingHandler.on_message()` event. |
| 56 |
|
| 57 |
.. autoclass:: proton.reactor.Container |
| 58 |
:show-inheritance: proton.reactor.Reactor |
| 59 |
:members: connect, create_receiver, create_sender, run, schedule |
| 60 |
:undoc-members: |
| 61 |
:noindex: |
| 62 |
|
| 63 |
.. py:attribute:: container_id |
| 64 |
|
| 65 |
The identifier used to identify this container in any |
| 66 |
connections it establishes. Container names should be |
| 67 |
unique. By default a UUID will be used. |
| 68 |
|
| 69 |
The :py:meth:`~proton.reactor.Container.connect()` method returns |
| 70 |
an instance of :py:class:`~proton.Connection`, the |
| 71 |
:py:meth:`~proton.reactor.Container.create_receiver()` method |
| 72 |
returns an instance of :py:class:`~proton.Receiver` and the |
| 73 |
:py:meth:`~proton.reactor.Container.create_sender()` method |
| 74 |
returns an instance of :py:class:`~proton.Sender`. |
| 75 |
|
| 76 |
.. autoclass:: proton.Connection |
| 77 |
:members: open, close, state, session, hostname, container, |
| 78 |
remote_container, remote_desired_capabilities, remote_hostname, remote_offered_capabilities , remote_properties |
| 79 |
:undoc-members: |
| 80 |
:noindex: |
| 81 |
|
| 82 |
.. autoclass:: proton.Receiver |
| 83 |
:show-inheritance: proton.Link |
| 84 |
:members: flow, recv, drain, draining |
| 85 |
:undoc-members: |
| 86 |
:noindex: |
| 87 |
|
| 88 |
.. autoclass:: proton.Sender |
| 89 |
:show-inheritance: proton.Link |
| 90 |
:members: offered, send |
| 91 |
:undoc-members: |
| 92 |
:noindex: |
| 93 |
|
| 94 |
.. autoclass:: proton.Link |
| 95 |
:members: name, state, is_sender, is_receiver, |
| 96 |
credit, queued, session, connection, |
| 97 |
source, target, remote_source, remote_target |
| 98 |
:undoc-members: |
| 99 |
:noindex: |
| 100 |
|
| 101 |
The :py:meth:`~proton.Link.source()`, |
| 102 |
:py:meth:`~proton.Link.target()`, |
| 103 |
:py:meth:`~proton.Link.remote_source()` and |
| 104 |
:py:meth:`~proton.Link.remote_target()` methods all return an |
| 105 |
instance of :py:class:`~proton.Terminus`. |
| 106 |
|
| 107 |
|
| 108 |
.. autoclass:: proton.Delivery |
| 109 |
:members: update, settle, settled, remote_state, local_state, partial, readable, writable, |
| 110 |
link, session, connection |
| 111 |
:undoc-members: |
| 112 |
:noindex: |
| 113 |
|
| 114 |
.. autoclass:: proton.handlers.MessagingHandler |
| 115 |
:members: on_start, on_reactor_init, |
| 116 |
on_message, |
| 117 |
on_accepted, |
| 118 |
on_rejected, |
| 119 |
on_settled, |
| 120 |
on_sendable, |
| 121 |
on_connection_error, |
| 122 |
on_link_error, |
| 123 |
on_session_error, |
| 124 |
on_disconnected, |
| 125 |
accept, reject, release, settle |
| 126 |
:undoc-members: |
| 127 |
:noindex: |
| 128 |
|
| 129 |
.. autoclass:: proton.Event |
| 130 |
:members: delivery, link, receiver, sender, session, connection, reactor, context |
| 131 |
:undoc-members: |
| 132 |
:noindex: |
| 133 |
|
| 134 |
.. autoclass:: proton.Message |
| 135 |
:members: address, id, priority, subject, ttl, reply_to, correlation_id, durable, user_id, |
| 136 |
content_type, content_encoding, creation_time, expiry_time, delivery_count, first_acquirer, |
| 137 |
group_id, group_sequence, reply_to_group_id, |
| 138 |
send, recv, encode, decode |
| 139 |
:undoc-members: |
| 140 |
:noindex: |
| 141 |
|
| 142 |
.. autoclass:: proton.Terminus |
| 143 |
:members: address, dynamic, properties, capabilities, filter |
| 144 |
:undoc-members: |
| 145 |
:noindex: |
| 146 |
|
| 147 |
.. _delivery-guarantees: |
| 148 |
|
| 149 |
=================== |
| 150 |
Delivery guarantees |
| 151 |
=================== |
| 152 |
|
| 153 |
For at-most-once, the sender settles the message as soon as it sends |
| 154 |
it. If the connection is lost before the message is received by the |
| 155 |
receiver, the message will not be delivered. |
| 156 |
|
| 157 |
For at-least-once, the receiver accepts and settles the message on |
| 158 |
receipt. If the connection is lost before the sender is informed of |
| 159 |
the settlement, then the delivery is considered in-doubt and should be |
| 160 |
retried. This will ensure it eventually gets delivered (provided of |
| 161 |
course the connection and link can be reestablished). It may mean that |
| 162 |
it is delivered multiple times though. |
| 163 |
|
| 164 |
Finally, for exactly-once, the receiver accepts the message but |
| 165 |
doesn't settle it. The sender settles once it is aware that the |
| 166 |
receiver accepted it. In this way the receiver retains knowledge of an |
| 167 |
accepted message until it is sure the sender knows it has been |
| 168 |
accepted. If the connection is lost before settlement, the receiver |
| 169 |
informs the sender of all the unsettled deliveries it knows about, and |
| 170 |
from this the sender can deduce which need to be redelivered. The |
| 171 |
sender likewise informs the receiver which deliveries it knows about, |
| 172 |
from which the receiver can deduce which have already been settled. |