pika/pika — Issue #133: Unable to detect publish failure when broker becomes unavailable.
Author: smetj
Created: 2012-03-02 09:37:29+00:00
State: open

Hi,

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

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))