python - RabbitMQ Message/Topic Receiver Crashing when RabbitMQ is not running -
i using python , pika on linux os environment. message/topic receiver keeps crashing when rabbitmq not running. wondering there way keep message/topic receiver running when rabbitmq not because rabbitmq not on same virtual machine message/topic receiver.
this cover if rabbitmq crashes reason message/topic receiver should keep running. saving having start/restart message/topic receiver again.
as far understand "message/topic reciever" in case consumer. responsible make application in such way catch exception if trying connect not running rabbitmq.
for example:
creds = pika.plaincredentials(**creds) params = pika.connectionparameters(credentials=creds, **conn_params) try: connection = pika.blockingconnection(params) log.info("connection rabbit established") return connection except (probableauthenticationerror, authenticationerror): log.error("authentication failed", exc_info=true) except probableaccessdeniederror: log.error("the virtual host configured wrong!", exc_info=true) except channelclosed: log.error("channelclosed error", exc_info=true) except amqpconnectionerror: log.error("rabbitmq server down or host unreachable") log.error("connection attempt timed out!") log.error("trying re-connect rabbitmq...") time.sleep(reconnection_interval) # <here goes reconnection logic >
and far making sure rabbit server , running:
- you can create cluster make queue durable, ha
install type of supervision (let monit or supervisord) , configure check rabbit process. example:
check process rabbitmq pidfile /var/run/rabbitmq/pid start program = "/etc/init.d/rabbitmq-server stop" stop program = "/etc/init.d/rabbitmq-server start" if 3 restarts within 5 cycles alert
Comments
Post a Comment