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()
|
||||
@@ -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 dead_letter_consumer.py"]
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import pika
|
||||
import time
|
||||
|
||||
connection = pika.BlockingConnection(pika.ConnectionParameters(host='rabbitmq', port=5672))
|
||||
channel = connection.channel()
|
||||
|
||||
|
||||
def callback(ch, method, properties, body):
|
||||
print('got new unprocessed message (body = "{}")'.format(body))
|
||||
ch.basic_ack(delivery_tag=method.delivery_tag)
|
||||
|
||||
|
||||
time.sleep(1)
|
||||
channel.basic_consume(queue='unprocessed_logs', 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:
|
||||
build:
|
||||
context: consumer
|
||||
dead_letter_consumer:
|
||||
build:
|
||||
context: dead_letter_consumer
|
||||
@@ -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,16 @@
|
||||
import pika
|
||||
import sys
|
||||
|
||||
connection = pika.BlockingConnection(pika.ConnectionParameters(host='rabbitmq', port=5672))
|
||||
channel = connection.channel()
|
||||
|
||||
channel.queue_declare(queue='unprocessed_logs')
|
||||
channel.queue_declare(queue='logs', arguments={
|
||||
'x-max-priority': 5,
|
||||
'x-dead-letter-exchange' : '',
|
||||
'x-dead-letter-routing-key' : 'unprocessed_logs'})
|
||||
|
||||
channel.basic_publish(exchange='', routing_key='logs', body='warning', properties=pika.BasicProperties(priority=1))
|
||||
channel.basic_publish(exchange='', routing_key='logs', body='error', properties=pika.BasicProperties(priority=5))
|
||||
channel.basic_publish(exchange='', routing_key='logs', body='info', properties=pika.BasicProperties(priority=1))
|
||||
connection.close()
|
||||
Reference in New Issue
Block a user