From fdec4a8c5df35087b3743315f34f368c7102ab49 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 14 May 2024 18:34:10 +0200 Subject: [PATCH] Update script for testing rabbitmq connections --- scripts/test-rabbitmq.connection.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/test-rabbitmq.connection.py b/scripts/test-rabbitmq.connection.py index 59d08373..c1cb77bd 100644 --- a/scripts/test-rabbitmq.connection.py +++ b/scripts/test-rabbitmq.connection.py @@ -2,23 +2,27 @@ import pika import logging +import os + +connection_string = os.getenv( + "RABBITMQ_URL", default="amqp://guest:guest@localhost:5672" +) + # create our logger logger = logging.getLogger(__name__) -# make sure have the logger set to level to +# make sure have the logger set to level to # accept the logging statements logger.setLevel(logging.DEBUG) -# create a handler for our logs, so we can see them +# create a handler for our logs, so we can see them console = logging.StreamHandler() # add the handler, so logs are shared as stream to STDOUT logger.addHandler(console) -connection = pika.BlockingConnection( - pika.URLParameters("amqp://guest:guest@localhost:5672") -) +connection = pika.BlockingConnection(pika.URLParameters(connection_string)) -# we need a channel to sent things to +# we need a channel to sent things to channel = connection.channel() channel.queue_declare(queue="hello") @@ -26,3 +30,5 @@ logger.info(" [x] Sent 'Hello World!'") connection.close() + +print(" [x] Sent 'Hello World!'")