[rabbitmq-discuss] Pika, Detect publish failure when broker becomes unavailable

Jelle Smet smetj.net at gmail.com
Fri Mar 2 00:08:58 GMT 2012


Hi all,

I'm using pika 0.9.5 and trying to figure out how to detect whether 
RabbitMQ is still available/unavailable after creating a connection to it.
When I stop Rabbit between the channel creation and publishing the message, 
there appears to be no way of detecting whether rabbit is still 
alive/available.
Publishing the message doesn't generate any error, connection.is_open 
always returns True...

Anyone an idea how to deal with this?

Cheers,

J


#!/usr/bin/python

import pika
from pika.adapters import SelectConnection
from pika.adapters import BlockingConnection
import time

parameters = pika.ConnectionParameters(host='sandbox')
connection = BlockingConnection(parameters)

channel = connection.channel()

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


time.sleep(10)
#I stop rabbitmq here

print connection.is_open #Returns True so this doesn't work


#this doesn't generate any error
channel.basic_publish(exchange='', routing_key="test", body="Hello World!",
                      
properties=pika.BasicProperties(content_type="text/plain", delivery_mode=1))

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120301/314b3ae1/attachment.htm>


More information about the rabbitmq-discuss mailing list