Last active
December 27, 2020 16:46
-
-
Save DhruvaDave/5384062a76e1159e812fcc0ec3fb5c0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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