| 1 |
#################################### |
| 2 |
Qpid Proton Python API Documentation |
| 3 |
#################################### |
| 4 |
|
| 5 |
The Proton module provides a Python 2.7 and 3.x API for Qpid Proton. It enables a developer to write Python applications |
| 6 |
that send and receive AMQP messages. |
| 7 |
|
| 8 |
******* |
| 9 |
Modules |
| 10 |
******* |
| 11 |
.. toctree:: |
| 12 |
:maxdepth: 2 |
| 13 |
|
| 14 |
proton |
| 15 |
proton.handlers |
| 16 |
proton.reactor |
| 17 |
proton.utils |
| 18 |
|
| 19 |
***************************************** |
| 20 |
About AMQP and the Qpid Proton Python API |
| 21 |
***************************************** |
| 22 |
|
| 23 |
.. toctree:: |
| 24 |
:maxdepth: 1 |
| 25 |
|
| 26 |
overview |
| 27 |
types |
| 28 |
tutorial |
| 29 |
|
| 30 |
Key API Features |
| 31 |
================ |
| 32 |
|
| 33 |
* Event-driven API |
| 34 |
* SSL/TLS secured communication |
| 35 |
* SASL authentication |
| 36 |
* Automatic reconnect and failover |
| 37 |
* Seamless conversion between AMQP and Python data types |
| 38 |
* AMQP 1.0 |
| 39 |
|
| 40 |
Basic API Concepts |
| 41 |
================== |
| 42 |
|
| 43 |
The Qpid Python client API and library allows applications to send and receive AMQP messages. See :ref:`overview` |
| 44 |
for a more detailed explanation. |
| 45 |
|
| 46 |
Containers |
| 47 |
---------- |
| 48 |
|
| 49 |
Messages are transferred between connected peers (or nodes) using **senders** and **receivers**. Each sender |
| 50 |
or receiver is established over a **connection**. Each connection is established between two unique **containers**, |
| 51 |
the entry point for the API. The container class :class:`proton.reactor.Container` is found in the ``proton.reactor`` |
| 52 |
module. |
| 53 |
|
| 54 |
Connections |
| 55 |
----------- |
| 56 |
|
| 57 |
A **connection** object tracks the status of an AMQP connection. For applications which *don't* require either |
| 58 |
authorization or encryption, these may be automatically created by convenience methods |
| 59 |
:meth:`proton.reactor.Container.create_sender` and/or :meth:`proton.reactor.Container.create_receiver`. |
| 60 |
However, for applications which *do* require either of these services, a connection object should be created |
| 61 |
using the convenience method :meth:`proton.reactor.Container.connect`, providing the required parameters. |
| 62 |
This object should then be passed to the convenience methods :meth:`proton.reactor.Container.create_sender` |
| 63 |
and/or :meth:`proton.reactor.Container.create_receiver` as needed. The connection class may be found at |
| 64 |
:class:`proton.Connection`. |
| 65 |
|
| 66 |
Senders |
| 67 |
------- |
| 68 |
|
| 69 |
The peer that sends messages uses a **sender** to send messages, which includes the target queue or topic which is |
| 70 |
to receive the messages. The sender may be found at :class:`proton.Sender`. Note that senders are most commonly |
| 71 |
obtained by using the convenience method :meth:`proton.reactor.Container.create_sender`. |
| 72 |
|
| 73 |
Receivers |
| 74 |
--------- |
| 75 |
|
| 76 |
The peer that receives messages uses a **receiver** to receive messages, and includes a source queue or topic from |
| 77 |
which to receive messages. The receiver may be found at :class:`proton.Receiver`. Note that senders are most commonly |
| 78 |
obtained by using the convenience method :meth:`proton.reactor.Container.create_receiver`. |
| 79 |
|
| 80 |
Message Delivery |
| 81 |
---------------- |
| 82 |
|
| 83 |
The process of sending a message is known as **delivery**. Each sent message has a delivery object which tracks the |
| 84 |
status of the message as it is sent from the sender to the receiver. This also includes actions such as settling the |
| 85 |
delivery (ie causing the delivery status to be forgotten when it is no longer needed). The delivery class may be found |
| 86 |
at :class:`proton.Delivery`. The delivery object is most commonly obtained |
| 87 |
when a message-related event occurs through the event object. See `Event Handlers`_ below. |
| 88 |
|
| 89 |
Event Handlers |
| 90 |
-------------- |
| 91 |
|
| 92 |
A **handler** is a class that handles events associated with the sending and receiving of messages. This includes |
| 93 |
callbacks for events such as the arrival of a new message, error conditions that might arise, and the closing |
| 94 |
of the connection over which messages are sent. An application developer must handle some key events to |
| 95 |
successfully send and receive messages. When an event handler callback is called by the library, an Event object is |
| 96 |
passed to it which contains an object associated with the event. For example, |
| 97 |
when a message is received, the event object will have the property ``event.message`` by which the message itself may |
| 98 |
be obtained. See :class:`proton.Event` for more details. |
| 99 |
|
| 100 |
The following are some of the important event callbacks that may be implemented by a developer: |
| 101 |
|
| 102 |
* **on_start()**: This indicates that the event loop in the container has started, and that a new sender and/or |
| 103 |
receiver may now be created. |
| 104 |
|
| 105 |
To send a message, the following events may need to be handled: |
| 106 |
|
| 107 |
* **on_sendable()**: This callback indicates that send credit has now been set by the receiver, and that a message may |
| 108 |
now be sent. |
| 109 |
* **on_accepted()**: This callback indicates that a message has been received and accepted by the receiving peer. |
| 110 |
|
| 111 |
To receive a message, the following event may need to be handled: |
| 112 |
|
| 113 |
* **on_message()**: This callback indicates that a message has been received. The message and its delivery object may |
| 114 |
be retreived, and if needed, the message can be either accepted or rejected. |
| 115 |
|
| 116 |
Many other events exist for the handling of transactions and other message events and errors, and if present in |
| 117 |
your handler will be called as the corresponding events arise. See the :ref:`tutorial` for examples of handling |
| 118 |
some other events. |
| 119 |
|
| 120 |
Several event handlers are provided which provide default behavior for most events. These may be found in the |
| 121 |
``proton.handlers`` module. The :class:`proton.handlers.MessagingHandler` is the most commonly used handler for |
| 122 |
non-transactional applications. Developers would typically directly inherit from this handler to provide the |
| 123 |
application's event behavior, and override callbacks as needed to provide additional behavior they may require. |
| 124 |
|
| 125 |
AMQP types |
| 126 |
---------- |
| 127 |
The types defined by the AMQP specification are mapped to either native Python types or to special proton classes |
| 128 |
which represent the AMQP type. See :ref:`types` for a summary. |
| 129 |
|
| 130 |
Examples |
| 131 |
-------- |
| 132 |
|
| 133 |
Several examples may be found in the |
| 134 |
`Apache Qpid Proton Examples <https://qpid.apache.org/releases/qpid-proton-0.28.0/proton/python/examples/index.html>`_ |
| 135 |
whcih illustrate the techniques and concepts of sending messages. They are also present in the source. These make |
| 136 |
an excellent starting point for developers new to this API. Make sure to read the README file, which gives |
| 137 |
instructions on how to run them and a brief explanation of each example. |
| 138 |
|
| 139 |
Tutorial |
| 140 |
-------- |
| 141 |
|
| 142 |
See this :ref:`tutorial` on using the API. |
| 143 |
|
| 144 |
Indices and tables |
| 145 |
================== |
| 146 |
|
| 147 |
* :ref:`genindex` |
| 148 |
* :ref:`search` |
| 149 |
|
| 150 |
.. * :ref:`modindex` |
| 151 |
Can't get this to generate, so commenting out. Also, not that useful in this case, as modules are listed |
| 152 |
in the contents above in full. |