Skip to content

Commit

Permalink
Update script for testing rabbitmq connections
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchrisadams committed May 14, 2024
1 parent f2dc55e commit fdec4a8
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions scripts/test-rabbitmq.connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@
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")

channel.basic_publish(exchange="", routing_key="hello", body="Hello World!")

logger.info(" [x] Sent 'Hello World!'")
connection.close()

print(" [x] Sent 'Hello World!'")

0 comments on commit fdec4a8

Please sign in to comment.