commit 8c3bc4f2170c3bc5d949adcfa3d1b0b624ffccdf Author: Torma Kristóf Date: Sat Apr 24 18:43:28 2021 +0200 some things done diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..615aafb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "/usr/bin/python3" +} \ No newline at end of file diff --git a/kafka/consumer.py b/kafka/consumer.py new file mode 100644 index 0000000..ac8d83d --- /dev/null +++ b/kafka/consumer.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python3 +from datetime import datetime + diff --git a/kafka/docker-compose.yml b/kafka/docker-compose.yml new file mode 100644 index 0000000..807f201 --- /dev/null +++ b/kafka/docker-compose.yml @@ -0,0 +1,20 @@ +version: "3" +services: + zookeeper: + image: 'bitnami/zookeeper:latest' + ports: + - '2181:2181' + environment: + - ALLOW_ANONYMOUS_LOGIN=yes + kafka: + image: 'bitnami/kafka:latest' + ports: + - '9092:9092' + environment: + - KAFKA_BROKER_ID=1 + - KAFKA_LISTENERS=PLAINTEXT://:9092 + - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092 + - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 + - ALLOW_PLAINTEXT_LISTENER=yes + depends_on: + - zookeeper diff --git a/kafka/publisher.py b/kafka/publisher.py new file mode 100644 index 0000000..e5a0d9b --- /dev/null +++ b/kafka/publisher.py @@ -0,0 +1 @@ +#!/usr/bin/env python3 diff --git a/rabbit/consumer.py b/rabbit/consumer.py new file mode 100644 index 0000000..62a20a5 --- /dev/null +++ b/rabbit/consumer.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +from datetime import datetime + +import pika + + +DATETIMES=[] + + +def callback(ch, method, properties, body): + DATETIMES.append(datetime.now()) + + +try: + n = 10 + credentials = pika.PlainCredentials("rabbit", "rabbit") + connection = pika.BlockingConnection(pika.ConnectionParameters(host="localhost", credentials=credentials, heartbeat=0, socket_timeout=5)) + channel = connection.channel() + channel.exchange_declare(exchange="test",exchange_type='direct') + queue_declare_result = channel.queue_declare(queue='testqueue', exclusive=False) + queue_name = queue_declare_result.method.queue + channel.queue_bind(exchange="test",routing_key='test', queue=queue_name) + channel.basic_qos(prefetch_count=1) + channel.basic_consume(queue=queue_name, on_message_callback=callback, auto_ack=True) + channel.start_consuming() +except Exception: + connection.close() + print(DATETIMES) diff --git a/rabbit/docker-compose.yml b/rabbit/docker-compose.yml new file mode 100644 index 0000000..930b1e8 --- /dev/null +++ b/rabbit/docker-compose.yml @@ -0,0 +1,10 @@ +version: "3" +services: + rabbitmq: + image: rabbitmq:3-management-alpine + environment: + RABBITMQ_DEFAULT_USER: rabbit + RABBITMQ_DEFAULT_PASS: rabbit + ports: + - 5672:5672 + - 15672:15672 diff --git a/rabbit/publisher.py b/rabbit/publisher.py new file mode 100644 index 0000000..b1fd22b --- /dev/null +++ b/rabbit/publisher.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +import pika +try: + n = 10 + credentials = pika.PlainCredentials("rabbit", "rabbit") + connection = pika.BlockingConnection(pika.ConnectionParameters(host="localhost", credentials=credentials, heartbeat=0, socket_timeout=5)) + channel = connection.channel() + channel.exchange_declare(exchange="test",exchange_type='direct') + string = "\"" + "a" * n + "\"" + while True: + channel.basic_publish(exchange="test",routing_key="test",body=string.encode('UTF-8')) +except Exception: + connection.close()