Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4411385

Browse files
committed
python/3 fixes
1 parent aa37689 commit 4411385

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

python/tutorial-three.mdx

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ digraph G {
1919
}
2020
{% enddot %}
2121

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
2525
different - we'll try to deliver a message to multiple consumers. This
2626
pattern is known as "publish-subscribe".
2727

2828
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.
3131

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
3333
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
3535
another reciver and see the same logs on the screen.
3636

37-
Essentially, crated log messages are going to be broadcasted to all
37+
Essentially, emited log messages are going to be broadcasted to all
3838
the receivers.
3939

4040

@@ -47,15 +47,15 @@ in Rabbit.
4747

4848
Let's quickly remind what we've learned:
4949

50-
* _Producer_ is a name for user application that sends messages.
50+
* _Producer_ is user application that sends messages.
5151
* _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.
5353

5454

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
5656
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!
5959

6060
Instead, the producer can only send messages to an _exchange_. An
6161
exchange is a very simple thing. On one side it receives messages from
@@ -81,7 +81,7 @@ digraph G {
8181

8282
There are a few exchange types available: `direct`, `topic`,
8383
`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`:
8585

8686
{% highlight python %}
8787
channel.exchange_declare(exchange='logs',
@@ -108,7 +108,7 @@ queues it knows. And that's exactly what we need for our logger.
108108
> ...done.
109109
>
110110
> 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.
112112

113113
<div></div>
114114

@@ -123,29 +123,27 @@ queues it knows. And that's exactly what we need for our logger.
123123
> routing_key='test',
124124
> body=message)
125125
>
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`.
130128

131129

132130

133131
Temporary queues
134132
----------------
135133

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
138136
queue was crucial for us - we needed to point the workers to the same
139137
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.
141139

142140
But that's not true for our logger. We do want to hear only about
143141
currently flowing log messages, we do not want to hear the old
144142
ones. To solve that problem we need two things.
145143

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
149147
`queue` parameter to `queue_declare`:
150148

151149
{% highlight python %}
@@ -189,7 +187,7 @@ between exchange and a queue is called a _binding_.
189187
queue=result.queue)
190188
{% endhighlight %}
191189

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
193191
our queue.
194192

195193
> #### Listing bindings
@@ -249,7 +247,7 @@ it's value is ignored for `fanout` exchanges. Here goes the code for
249247
body=message)
250248
print " [x] Sent %r" % (message,)
251249
{% endhighlight %}
252-
[(full emit_log.py source)]({{ examples_url }}/python/emit_log.py)
250+
[(emit_log.py source)]({{ examples_url }}/python/emit_log.py)
253251

254252
As you see, we avoided declaring exchange. If the `logs` exchange
255253
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:
297295

298296
$ ./receive_logs.py
299297

298+
And of course, to emit logs type:
299+
300+
$ ./emit_log.py
300301

python/tutorial-two.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ Final code of our `new_task.py` script:
305305
))
306306
print " [x] Sent %r" % (message,)
307307
{% endhighlight %}
308-
[(full new_task.py source)]({{ examples_url }}/python/new_task.py)
308+
[(new_task.py source)]({{ examples_url }}/python/new_task.py)
309309

310310

311311
And our worker:
@@ -335,7 +335,7 @@ And our worker:
335335

336336
pika.asyncore_loop()
337337
{% endhighlight %}
338-
[(full worker.py source)]({{ examples_url }}/python/worker.py)
338+
[(worker.py source)]({{ examples_url }}/python/worker.py)
339339

340340

341341
Using message acknowledgments and `prefetch_count` you may set up

0 commit comments

Comments
 (0)