Add week 5 materials
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
FROM python:3.8
|
||||
|
||||
RUN mkdir /root/app/
|
||||
WORKDIR /root/app/
|
||||
|
||||
RUN pip install pika
|
||||
|
||||
COPY . .
|
||||
|
||||
ENV PYTHONPATH "${PYTHONPATH}:/root/app/"
|
||||
EXPOSE 5000
|
||||
|
||||
CMD ["bash", "-c", "while ! curl -s rabbitmq:15672 > /dev/null; do echo waiting for rabbitmq; sleep 3; done; python -u consumer.py"]
|
||||
@@ -0,0 +1,21 @@
|
||||
import pika
|
||||
import time
|
||||
|
||||
connection = pika.BlockingConnection(pika.ConnectionParameters(host='rabbitmq', port=5672))
|
||||
channel = connection.channel()
|
||||
|
||||
|
||||
def callback(ch, method, properties, body):
|
||||
if body.startswith(b'warning'):
|
||||
print('got new warning (body = "{}")'.format(body))
|
||||
ch.basic_ack(delivery_tag=method.delivery_tag)
|
||||
elif body.startswith(b'error'):
|
||||
print('got new error (body = "{}")'.format(body))
|
||||
ch.basic_ack(delivery_tag=method.delivery_tag)
|
||||
else:
|
||||
ch.basic_nack(delivery_tag=method.delivery_tag, requeue=False)
|
||||
|
||||
|
||||
time.sleep(1)
|
||||
channel.basic_consume(queue='logs', on_message_callback=callback)
|
||||
channel.start_consuming()
|
||||
Reference in New Issue
Block a user