-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update documentation for mandatory flag with BlockingConnection
- Loading branch information
1 parent
42ca6d0
commit 61c3fb6
Showing
1 changed file
with
11 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
Ensuring message delivery with the mandatory flag | ||
================================================= | ||
|
||
The following example demonstrates how to check if a message is delivered by setting the mandatory flag and checking the return result when using the BlockingConnection:: | ||
The following example demonstrates how to check if a message is delivered by setting the mandatory flag and handling exceptions when using the BlockingConnection:: | ||
|
||
import pika | ||
import pika.exceptions | ||
|
||
# Open a connection to RabbitMQ on localhost using all default parameters | ||
connection = pika.BlockingConnection() | ||
|
@@ -14,16 +15,17 @@ The following example demonstrates how to check if a message is delivered by set | |
# Declare the queue | ||
channel.queue_declare(queue="test", durable=True, exclusive=False, auto_delete=False) | ||
|
||
# Enabled delivery confirmations | ||
# Enabled delivery confirmations. This is REQUIRED. | ||
channel.confirm_delivery() | ||
|
||
# Send a message | ||
if channel.basic_publish(exchange='test', | ||
routing_key='test', | ||
body='Hello World!', | ||
properties=pika.BasicProperties(content_type='text/plain', | ||
delivery_mode=1), | ||
mandatory=True): | ||
try: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
lukebakken
Author
Member
|
||
channel.basic_publish(exchange='test', | ||
routing_key='test', | ||
body='Hello World!', | ||
properties=pika.BasicProperties(content_type='text/plain', | ||
delivery_mode=1), | ||
mandatory=True): | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
lukebakken
Author
Member
|
||
print('Message was published') | ||
else: | ||
except pika.exceptions.UnroutableError: | ||
print('Message was returned') |
Missing indentation