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_all.py"]
|
||||
@@ -0,0 +1,23 @@
|
||||
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='#')
|
||||
|
||||
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()
|
||||
@@ -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()
|
||||
@@ -0,0 +1,18 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
rabbitmq:
|
||||
image: rabbitmq:3-management
|
||||
hostname: "rabbitmq"
|
||||
ports:
|
||||
- "15672:15672"
|
||||
- "5672:5672"
|
||||
producer:
|
||||
build:
|
||||
context: producer
|
||||
consumer_all:
|
||||
build:
|
||||
context: consumer_all
|
||||
consumer_critical:
|
||||
build:
|
||||
context: consumer_critical
|
||||
@@ -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 producer.py"]
|
||||
@@ -0,0 +1,15 @@
|
||||
import pika
|
||||
import time
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
connection = pika.BlockingConnection(pika.ConnectionParameters(host='rabbitmq', port=5672))
|
||||
channel = connection.channel()
|
||||
|
||||
channel.exchange_declare(exchange='topic_logs', exchange_type='topic')
|
||||
|
||||
time.sleep(2)
|
||||
channel.basic_publish(exchange='topic_logs', routing_key='kernel.critical', body='critical error')
|
||||
channel.basic_publish(exchange='topic_logs', routing_key='monitoring.warning', body='warning')
|
||||
channel.basic_publish(exchange='topic_logs', routing_key='production.kernel.critical', body='another critical error')
|
||||
connection.close()
|
||||
Reference in New Issue
Block a user