summaryrefslogtreecommitdiff
path: root/trunk/qpid/python/examples/README
blob: bd30b2a6f41fc4513fd10201eff0ca3c48dd2dc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
Running the Python Examples
============================


Running the Direct Examples
----------------------------

To run the direct examples, do the following:

1. Make sure that a qpidd broker is running:

 $ ps -eaf | grep qpidd

  If a broker is running, you should see the qpidd process in the output of the above command. 

2.Declare a message queue and bind it to an exchange by running declare_queues.py, as follows:

 $ python declare_queues.py

 This program has no output. After this program has been run, all messages sent to the amq.direct exchange using the routing key routing_key are sent to the queue named message_queue.

3.Publish a series of messages to the amq.direct exchange by running direct_producer.py, as follows:

 $ python direct_producer.py

This program has no output; the messages are routed to the message queue, as instructed by the binding.

4. Read the messages from the message queue using direct_consumer.py or listener.py, as follows:

 $ python direct_consumer.py

 or

 $ python listener.py

You should see the following output:

message 0
message 1
message 2
message 3
message 4
message 5
message 6
message 7
message 8
message 9
That's all, folks!



Running the Fanout Examples
----------------------------

To run the programs for the Fanout example, do the following:

1. Make sure that a qpidd broker is running:

  $ ps -eaf | grep qpidd

If a broker is running, you should see the qpidd process in the output of the above command.  

2. In separate windows, start two or more fanout consumers or fanout listeners as follows:

  $ python fanout_consumer.py

  or

  $ python listener.py

These programs each create a private queue, bind it to the amq.fanout exchange, and wait for messages to arrive on their queue.

3. In a separate window, publish a series of messages to the amq.fanout exchange by running fanout_producer.py, as follows:

  $ python fanout_producer.py

This program has no output; the messages are routed to the message queue, as instructed by the binding.
 
4. Go to the windows where you are running consumers or listeners. You should see the following output for each listener or consumer:

      message 0
      message 1
      message 2
      message 3
      message 4
      message 5
      message 6
      message 7
      message 8
      message 9
      That's all, folks!



Running the Publish-Subscribe Examples
---------------------------------------

To run the programs for the Publish-Subscribe example, do the following:

1. Make sure that a qpidd broker is running:

  $ ps -eaf | grep qpidd

If a broker is running, you should see the qpidd process in the output of the above command. 

2. In separate windows, start one or more topic subscribers by running topic_subscriber.py, as follows:

  $ python topic_subscriber.py

You will see output similar to this:

  Queues created - please start the topic producer
  Subscribing local queue 'local_news' to news-53408183-fcee-4b92-950b-90abb297e739'
  Subscribing local queue 'local_weather' to weather-53408183-fcee-4b92-950b-90abb297e739'
  Subscribing local queue 'local_usa' to usa-53408183-fcee-4b92-950b-90abb297e739'
  Subscribing local queue 'local_europe' to europe-53408183-fcee-4b92-950b-90abb297e739'
  Messages on 'news' queue:

Each topic consumer creates a set of private queues, and binds each queue to the amq.topic exchange together with a binding that indicates which messages should be routed to the queue.

3.In another window, start the topic publisher, which publishes messages to the amq.topic exchange, as follows:

  $ python topic_publisher.py

This program has no output; the messages are routed to the message queues for each topic_consumer as specified by the bindings the consumer created.

4. Go back to the window for each topic consumer. You should see output like this:

      Messages on 'news' queue:
      usa.news 0
      usa.news 1
      usa.news 2
      usa.news 3
      usa.news 4
      europe.news 0
      europe.news 1
      europe.news 2
      europe.news 3
      europe.news 4
      That's all, folks!
      Messages on 'weather' queue:
      usa.weather 0
      usa.weather 1
      usa.weather 2
      usa.weather 3
      usa.weather 4
      europe.weather 0
      europe.weather 1
      europe.weather 2
      europe.weather 3
      europe.weather 4
      That's all, folks!
      Messages on 'usa' queue:
      usa.news 0
      usa.news 1
      usa.news 2
      usa.news 3
      usa.news 4
      usa.weather 0
      usa.weather 1
      usa.weather 2
      usa.weather 3
      usa.weather 4
      That's all, folks!
      Messages on 'europe' queue:
      europe.news 0
      europe.news 1
      europe.news 2
      europe.news 3
      europe.news 4
      europe.weather 0
      europe.weather 1
      europe.weather 2
      europe.weather 3
      europe.weather 4
      That's all, folks!


Running the Request/Response Examples
--------------------------------------

To run the programs for the Request/Response example, do the following:

1. Make sure that a qpidd broker is running:

  $ ps -eaf | grep qpidd

If a broker is running, you should see the qpidd process in the output of the above command.

2. Run the server.

  $ python server.py

You should see the following output:

  Request server running - run your client now.
  (Times out after 100 seconds ...)

3. In a separate window, start a client:

  $ python client.py

You should see the following output:

      Request: Twas brillig, and the slithy toves
      Request: Did gyre and gimble in the wabe.
      Request: All mimsy were the borogroves,
      Request: And the mome raths outgrabe.
      Messages on queue: reply_to:db0f862e-6b36-4e0f-a4b2-ad049eb435ce
      Response: TWAS BRILLIG, AND THE SLITHY TOVES
      Response: DID GYRE AND GIMBLE IN THE WABE.
      Response: ALL MIMSY WERE THE BOROGROVES,
      Response: AND THE MOME RATHS OUTGRABE.
      No more messages!


Running the XML-based Routing Examples
---------------------------------------

To run the programs for the XML-based Routing example, do the following:

1. Make sure that a qpidd broker is running:

  $ ps -eaf | grep qpidd

If a broker is running, you should see the qpidd process in the output of the above command.

2. Declare an XML exchange and a message queue, then bind the queue to the exchange by running declare_queues.py, as follows:

  $ python declare_queues.py

This program has no output. After this program has been run, all messages sent to the xml exchange using the routing key weather are sent to the queue named message_queue if they satisfy the conditions specified in the following XQuery, which is used in the binding:

 let $w := ./weather
 return $w/station = 'Raleigh-Durham International Airport (KRDU)'
    and $w/temperature_f > 50
    and $w/temperature_f - $w/dewpoint > 5
    and $w/wind_speed_mph > 7
    and $w/wind_speed_mph < 20

3. Publish a series of messages to the xml exchange by running xml_producer.py, as follows:

  $ python xml_producer.py

The messages are routed to the message queue, as prescribed by the binding. Each message represents a weather report, such as this one:

  <weather>
      <station>Raleigh-Durham International Airport (KRDU)</station>
      <wind_speed_mph>16</wind_speed_mph>
      <temperature_f>70</temperature_f>
      <dewpoint>35</dewpoint>
  </weather>

4. Read the messages from the message queue using direct_consumer.py or listener.py, as follows:

  $ python xml_consumer.py

  or

  $ python listener.py

You should see the following output:

<weather><station>Raleigh-Durham International Airport (KRDU)</station>
<wind_speed_mph>16</wind_speed_mph><temperature_f>70</temperature_f>
<dewpoint>35</dewpoint></weather>


Running the Headers Examples
-----------------------------

To run the headers examples, do the following:

1. Make sure that a qpidd broker is running:

 $ ps -eaf | grep qpidd

  If a broker is running, you should see the qpidd process in the output of the above command. 

2.Declare a message queues and bind them to an exchange by running declare_queues.py, as follows:

 $ python declare_queues.py

 This program has no output. After this program has been run, all messages sent to the amq.match exchange with an application-header of {'class': 'first'} will be routed to the queue named "first" and messages with an application-header of {'class': 'second'} will be routed to the queue named "second".

3.Publish a series of messages to the amq.match exchange by running headers_producer.py, as follows:

 $ python headers_producer.py

This program has no output; the messages are routed to the message queues, as instructed by the bindings.

4. Read the messages from the message queues using headers_consumer.py as follows:

 $ python headers_consumer.py

You should see the following output:

message(first) 0
message(first) 1
message(first) 2
message(first) 3
message(first) 4
message(first) 5
message(first) 6
message(first) 7
message(first) 8
message(first) 9
That's all, folks!
message(second) 0
message(second) 1
message(second) 2
message(second) 3
message(second) 4
message(second) 5
message(second) 6
message(second) 7
message(second) 8
message(second) 9
That's all, folks!