File: blocking_publish_mandatory.rst

package info (click to toggle)
python-pika 0.9.14-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,048 kB
  • ctags: 2,110
  • sloc: python: 10,046; makefile: 134
file content (26 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download | duplicates (2)
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
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::

    import pika

    # Open a connection to RabbitMQ on localhost using all default parameters
    connection = pika.BlockingConnection()

    # Open the channel
    channel = connection.channel()

    # Declare the queue
    channel.queue_declare(queue="test", durable=True, exclusive=False, auto_delete=False)

    # 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):
        print 'Message was published'
    else:
        print 'Message was returned'