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_critical.py"]
|
||||
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
import pika
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
connection = pika.BlockingConnection(pika.ConnectionParameters(host='rabbitmq', port=5672))
|
||||
channel = connection.channel()
|
||||
|
||||
channel.exchange_declare(exchange='topic_logs', exchange_type='topic')
|
||||
|
||||
result = channel.queue_declare(queue='', exclusive=True)
|
||||
queue_name = result.method.queue
|
||||
|
||||
channel.queue_bind(exchange='topic_logs', queue=queue_name, routing_key='*.critical')
|
||||
|
||||
print(' [*] Waiting for logs.')
|
||||
|
||||
def callback(ch, method, properties, body):
|
||||
print(f" [x] {method.routing_key}:{body.decode()}")
|
||||
ch.basic_ack(delivery_tag=method.delivery_tag)
|
||||
|
||||
channel.basic_consume(queue=queue_name, on_message_callback=callback)
|
||||
|
||||
channel.start_consuming()
|
||||
Reference in New Issue
Block a user