| 1 |
Most (though not all) of the current examples require a broker or |
| 2 |
similar intermediary that supports the AMQP 1.0 protocol, allows |
| 3 |
anonymous connections and accepts links to and from a node named |
| 4 |
'examples'. A very simple broker emulating script - broker.py - is |
| 5 |
provided against which some of the examples can also be run. |
| 6 |
|
| 7 |
Transactions and selectors are not yet supported in this script, so the |
| 8 |
examples that require these features (tx_recy.py, tx_send.py, |
| 9 |
tx_recv_interactive.py, server_tx.py & selected_recv.py) need to be run |
| 10 |
with a broker that supports these features (for instance the qpidd broker) |
| 11 |
|
| 12 |
There is a test script that will run most of the examples. This script needs |
| 13 |
a broker to be running already as a prerequisite. As this script runs the |
| 14 |
transactional and selector requiring examples this broker must support these |
| 15 |
features. |
| 16 |
|
| 17 |
For example: |
| 18 |
qpidd --queue-patterns '.*' & |
| 19 |
PATH=.:$PATH python -m unittest -v |
| 20 |
run from within the examples directory |
| 21 |
|
| 22 |
Note: For builds that include SASL support via the cyrus sasl library, |
| 23 |
those examples that accept incoming connections may require some SASL |
| 24 |
configuration which is described below. |
| 25 |
|
| 26 |
------------------------------------------------------------------ |
| 27 |
|
| 28 |
helloworld.py |
| 29 |
|
| 30 |
Basic example that connects to an intermediary on localhost:5672, |
| 31 |
establishes a subscription from the 'examples' node on that |
| 32 |
intermediary, then creates a sending link to the same node and sends |
| 33 |
one message. On receiving the message back via the subscription, the |
| 34 |
connection is closed. |
| 35 |
|
| 36 |
helloworld_blocking.py |
| 37 |
|
| 38 |
The same as the basic helloworld.py, but using a |
| 39 |
synchronous/sequential style wrapper on top of the |
| 40 |
asynchronous/reactive API. The purpose of this example is just to show |
| 41 |
how different functionality can be easily layered should it be |
| 42 |
desired. |
| 43 |
|
| 44 |
helloworld_direct.py |
| 45 |
|
| 46 |
A variant of the basic helloworld example, that does not use an |
| 47 |
intermediary, but listens for incoming connections itself. It |
| 48 |
establishes a connection to itself with a link over which a single |
| 49 |
message is sent. This demonstrates the ease with which a simple daemon |
| 50 |
can be built using the API. |
| 51 |
|
| 52 |
helloworld_tornado.py |
| 53 |
helloworld_direct_tornado.py |
| 54 |
|
| 55 |
These are variant of the helloworld.py and helloworld_direct.py |
| 56 |
examples that use the event loop from the tornado library, rather than |
| 57 |
that provided within proton itself and demonstrate how proton can be |
| 58 |
used with external loops. |
| 59 |
|
| 60 |
------------------------------------------------------------------- |
| 61 |
|
| 62 |
simple_send.py |
| 63 |
|
| 64 |
An example of sending a fixed number of messages and tracking their |
| 65 |
(asynchronous) acknowledgement. Handles disconnection while |
| 66 |
maintaining an at-least-once guarantee (there may be duplicates, but |
| 67 |
no message in the sequence should be lost). Messages are sent through |
| 68 |
the 'examples' node on an intermediary accessible on port 5672 on |
| 69 |
localhost. |
| 70 |
|
| 71 |
simple_recv.py |
| 72 |
|
| 73 |
Subscribes to the 'examples' node on an intermediary accessible on port 5672 on |
| 74 |
localhost. Simply prints out the body of received messages. |
| 75 |
|
| 76 |
db_send.py |
| 77 |
|
| 78 |
A more realistic sending example, where the messages come from records |
| 79 |
in a simple database table. On being acknowledged the records can be |
| 80 |
deleted from the table. The database access is done in a separate |
| 81 |
thread, so as not to block the event thread during data |
| 82 |
access. Messages are sent through the 'examples' node on an |
| 83 |
intermediary accessible on port 5672 on localhost. |
| 84 |
|
| 85 |
db_recv.py |
| 86 |
|
| 87 |
A receiving example that records messages received from the 'examples' |
| 88 |
node on localhost:5672 in a database table and only acknowledges them |
| 89 |
when the insert completes. Database access is again done in a separate |
| 90 |
thread from the event loop. |
| 91 |
|
| 92 |
db_ctrl.py |
| 93 |
|
| 94 |
A utility for setting up the database tables for the two examples |
| 95 |
above. Takes two arguments, the action to perform and the name of the |
| 96 |
database on which to perform it. The database used by db_send.py is |
| 97 |
src_db, that by db_recv.py is dst_db. The valid actions are 'init', |
| 98 |
which creates the table, 'list' which displays the contents and |
| 99 |
'insert' which inserts records from standard-in and is used to |
| 100 |
populate src_db, e.g. for i in `seq 1 50`; do echo "Message-$i"; done |
| 101 |
| ./db_ctrl.py insert src_db. |
| 102 |
|
| 103 |
tx_send.py |
| 104 |
|
| 105 |
A sender that sends messages in atomic batches using local |
| 106 |
transactions (this example does not persist the messages in any way). |
| 107 |
|
| 108 |
tx_recv.py |
| 109 |
|
| 110 |
A receiver example that accepts batches of messages using local |
| 111 |
transactions. |
| 112 |
|
| 113 |
tx_recv_interactive.py |
| 114 |
|
| 115 |
A testing utility that allow interactive control of the |
| 116 |
transactions. Actions are keyed in to the console, 'fetch' will |
| 117 |
request another message, 'abort' will abort the transaction, 'commit' |
| 118 |
will commit it. |
| 119 |
|
| 120 |
The various send/recv examples can be mixed and matched if desired. |
| 121 |
|
| 122 |
direct_send.py |
| 123 |
|
| 124 |
An example that accepts incoming links and connections over which it |
| 125 |
will then send out messages. Can be used with simple_recv.py or |
| 126 |
db_recv.py for direct, non-intermediated communication. |
| 127 |
|
| 128 |
direct_recv.py |
| 129 |
|
| 130 |
An example that accepts incoming links and connections over which it |
| 131 |
will then receive messages, printing out the content. Can be used with |
| 132 |
simple_send.py or db_send.py for direct, non-intermediated |
| 133 |
communication. |
| 134 |
|
| 135 |
------------------------------------------------------------------- |
| 136 |
|
| 137 |
client.py |
| 138 |
|
| 139 |
The client part of a request-response example. Sends requests and |
| 140 |
prints out responses. Requires an intermediary that supports the AMQP |
| 141 |
1.0 dynamic nodes on which the responses are received. The requests |
| 142 |
are sent through the 'examples' node. |
| 143 |
|
| 144 |
server.py |
| 145 |
|
| 146 |
The server part of a request-response example, that receives requests |
| 147 |
via the examples node, converts the body to uppercase and sends the |
| 148 |
result back to the indicated reply address. |
| 149 |
|
| 150 |
sync_client.py |
| 151 |
|
| 152 |
A variant of the client part, that uses a blocking/synchronous style |
| 153 |
instead of the reactive/asynchronous style. |
| 154 |
|
| 155 |
client_http.py |
| 156 |
|
| 157 |
A variant of the client part that takes the input to be submitted in |
| 158 |
the request over HTTP (point your browser to localhost:8888/client) |
| 159 |
|
| 160 |
server_tx.py |
| 161 |
|
| 162 |
A variant of the server part that consumes the request and sends out |
| 163 |
the response atomically in a local transaction. |
| 164 |
|
| 165 |
direct_server.py |
| 166 |
|
| 167 |
A variant of the server part of a request-response example, that |
| 168 |
accepts incoming connections and does not need an intermediary. Much |
| 169 |
like the original server, it receives incoming requests, converts the |
| 170 |
body to uppercase and sends the result back to the indicated reply |
| 171 |
address. Can be used in conjunction with any of the client |
| 172 |
alternatives. |
| 173 |
|
| 174 |
------------------------------------------------------------------- |
| 175 |
|
| 176 |
selected_recv.py |
| 177 |
|
| 178 |
An example that uses a selector filter. |
| 179 |
|
| 180 |
------------------------------------------------------------------- |
| 181 |
|
| 182 |
recurring_timer.py |
| 183 |
|
| 184 |
An example showing a simple timer event. |
| 185 |
|
| 186 |
recurring_timer_tornado.py |
| 187 |
|
| 188 |
A variant of the above that uses the tornado eventloop instead. |
| 189 |
|
| 190 |
------------------------------------------------------------------- |
| 191 |
|
| 192 |
SASL configuration |
| 193 |
|
| 194 |
If your build includes extra SASL support (provided via the cyrus SASL |
| 195 |
library), you may need to provide some configuration to enable |
| 196 |
examples that accept incoming connections (i.e. those with 'direct' in |
| 197 |
the name). This is done by supplying a config file name |
| 198 |
proton-server.conf. The directory in which it is in can be specified |
| 199 |
via the PN_SASL_CONFIG_PATH environment variable. A simple example |
| 200 |
config file is included along with these examples, enabling only the |
| 201 |
EXTERNAL and ANONYMOUS mechanisms by default. |