Skip to content

Instantly share code, notes, and snippets.

@DhruvaDave
Last active December 27, 2020 16:46
Show Gist options
  • Save DhruvaDave/5384062a76e1159e812fcc0ec3fb5c0c to your computer and use it in GitHub Desktop.
Save DhruvaDave/5384062a76e1159e812fcc0ec3fb5c0c to your computer and use it in GitHub Desktop.
import pika
print(' Connecting to server ...')
try:
connection = pika.BlockingConnection(pika.ConnectionParameters(host="rabbitmq"))
except pika.exceptions.AMQPConnectionError as exc:
print("Failed to connect to RabbitMQ service. Message wont be sent.")
return
channel = connection.channel()
channel.queue_declare(queue='task_queue', durable=True)
print(' Waiting for messages...')
def callback(ch, method, properties, body):
print(" Received %s" % body.decode())
print(" Done")
ch.basic_ack(delivery_tag=method.delivery_tag)
channel.basic_qos(prefetch_count=1)
channel.basic_consume(queue='task_queue', on_message_callback=callback)
channel.start_consuming()
FROM ubuntu:18.04
RUN apt-get update -y && \
apt-get install -y python3-pip python3-dev
RUN pip3 install pika
WORKDIR /app
COPY . /app
ENTRYPOINT [ "python3" ]
CMD [ "app.py" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment