File: blocking_delivery_confirmations.rst

package info (click to toggle)
python-pika 1.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,064 kB
  • sloc: python: 20,886; makefile: 136
file content (29 lines) | stat: -rw-r--r-- 1,159 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
27
28
29
Using Delivery Confirmations with the BlockingConnection
========================================================

The following code demonstrates how to turn on delivery confirmations with the BlockingConnection and how to check for confirmation from RabbitMQ::

    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)

    # Turn on delivery confirmations
    channel.confirm_delivery()

    # Send a message
    try:
        channel.basic_publish(exchange='test',
                              routing_key='test',
                              body='Hello World!',
                              properties=pika.BasicProperties(content_type='text/plain',
                                                              delivery_mode=pika.DeliveryMode.Transient)):
        print('Message publish was confirmed')
    except pika.exceptions.UnroutableError:
        print('Message could not be confirmed')