@@ -19,22 +19,22 @@ digraph G {
19
19
}
20
20
{ % enddot % }
21
21
22
- In previous part of this tutorial we've learned how to create a task
23
- queue. The idea behind a task queue is that a task should be delivered
24
- to exactly one worker. In this part we'll do something completely
22
+ In [ previous part]( { { python_two_url } } ) of this tutorial we've learned how
23
+ to create a task queue. The core assumption behind a task queue is that a task
24
+ is delivered to exactly one worker. In this part we'll do something completely
25
25
different - we'll try to deliver a message to multiple consumers. This
26
26
pattern is known as "publish-subscribe".
27
27
28
28
To illustrate this this tutorial, we're going to build a simple
29
- logging system. It will consist of two programs - one will emit log
30
- messages and one will receive them.
29
+ logging system. It will consist of two programs - first will emit log
30
+ messages and second will receive and print them.
31
31
32
- In our logging system we'll every running copy of the receiver program
32
+ In our logging system every running copy of the receiver program
33
33
will be able to get the same messages. That way we'll be able to run one
34
- receiver and direct the logs to disk. In the same time we'll be able to run
34
+ receiver and direct the logs to disk, in the same time we'll be able to run
35
35
another reciver and see the same logs on the screen.
36
36
37
- Essentially, crated log messages are going to be broadcasted to all
37
+ Essentially, emited log messages are going to be broadcasted to all
38
38
the receivers.
39
39
40
40
@@ -47,15 +47,15 @@ in Rabbit.
47
47
48
48
Let's quickly remind what we've learned:
49
49
50
- * _Producer_ is a name for user application that sends messages.
50
+ * _Producer_ is user application that sends messages.
51
51
* _Queue_ is a buffer that stores messages.
52
- * _Consumer_ is a name for user application that receives messages.
52
+ * _Consumer_ is user application that receives messages.
53
53
54
54
55
- The core idea behind the messaging model in Rabbit is that the
55
+ The core idea in the messaging model in Rabbit is that the
56
56
producer never sends any messages directly to the queue. Actually,
57
- quite often the producer doesn't even know that a message won't be
58
- delivered to any queue!
57
+ quite often the producer doesn't even know if a message will be
58
+ delivered to any queue at all !
59
59
60
60
Instead, the producer can only send messages to an _exchange_. An
61
61
exchange is a very simple thing. On one side it receives messages from
@@ -81,7 +81,7 @@ digraph G {
81
81
82
82
There are a few exchange types available: `direct`, `topic`,
83
83
`headers` and `fanout`. We'll focus on the last one - the
84
- fanout. Let's create an exchange of that type, and name it `logs`:
84
+ fanout. Let's create an exchange of that type, and call it `logs`:
85
85
86
86
{ % highlight python % }
87
87
channel.exchange_declare(exchange='logs',
@@ -108,7 +108,7 @@ queues it knows. And that's exactly what we need for our logger.
108
108
> ...done.
109
109
>
110
110
> You can see a few `amq.` exchanges. They're created by default, but with a
111
- > bit of good luck you'll never need to use them.
111
+ > bit of luck you'll never need to use them.
112
112
113
113
<div ></div >
114
114
@@ -123,29 +123,27 @@ queues it knows. And that's exactly what we need for our logger.
123
123
> routing_key='test',
124
124
> body=message)
125
125
>
126
- > The _empty string_ exchange is a special exchange: every queue is connected
127
- > to it using its queue name as a key. When you publish a message to the
128
- > nameless exchange it will be routed to the queue with name specified
129
- > by `routing_key`.
126
+ > The _empty string_ exchange is special: message is
127
+ > routed to the queue with name specified by `routing_key`.
130
128
131
129
132
130
133
131
Temporary queues
134
132
----------------
135
133
136
- In previous tutorial parts we were using a queue which had a name -
137
- `test` in first `test_dur ` in second tutorial. Being able to name a
134
+ As you may remember previously we were using queues which had a specified name -
135
+ `test` in first `task_queue ` in second tutorial. Being able to name a
138
136
queue was crucial for us - we needed to point the workers to the same
139
137
queue. Essentially, giving a queue a name is important when you don't
140
- want to loose any messages if the consumer disconnects.
138
+ want to loose any messages when the consumer disconnects.
141
139
142
140
But that's not true for our logger. We do want to hear only about
143
141
currently flowing log messages, we do not want to hear the old
144
142
ones. To solve that problem we need two things.
145
143
146
- First, whenever we connect the queue should be new and empty. To do it
147
- we could just use random queue name, or, even better - let server to
148
- choose a random unique queue name. We can do it by not supplying the
144
+ First, whenever we connect to Rabbit we need a fresh, empty queue . To do it
145
+ we could create a queue with a random name, or, even better - let server
146
+ choose a random queue name for us . We can do it by not supplying the
149
147
`queue` parameter to `queue_declare`:
150
148
151
149
{ % highlight python % }
@@ -189,7 +187,7 @@ between exchange and a queue is called a _binding_.
189
187
queue=result.queue)
190
188
{ % endhighlight % }
191
189
192
- From now on the `logs` exchange will broadcast the messages also to
190
+ From now on the `logs` exchange will broadcast all the messages also to
193
191
our queue.
194
192
195
193
> #### Listing bindings
@@ -249,7 +247,7 @@ it's value is ignored for `fanout` exchanges. Here goes the code for
249
247
body=message)
250
248
print " [x] Sent %r" % (message,)
251
249
{ % endhighlight % }
252
- [(full emit_log.py source)]({ { examples_url }} /python/emit_log.py)
250
+ [(emit_log.py source)]({ { examples_url }} /python/emit_log.py)
253
251
254
252
As you see, we avoided declaring exchange. If the `logs` exchange
255
253
isn't created at the time this code is executed the message will be
@@ -297,4 +295,7 @@ If you wish to see the logs on your screen, spawn a new terminal and run:
297
295
298
296
$ ./receive_logs.py
299
297
298
+ And of course, to emit logs type:
299
+
300
+ $ ./emit_log.py
300
301
0 commit comments