A kiválasztott változat és az aktuális verzió közötti különbségek a következők.
Előző változat mindkét oldalon Előző változat Következő változat | Előző változat | ||
tanszek:oktatas:iss_t:rabbitmq [2023/05/08 08:28] knehez |
tanszek:oktatas:iss_t:rabbitmq [2023/06/27 12:38] (aktuális) knehez |
||
---|---|---|---|
Sor 13: | Sor 13: | ||
<code> | <code> | ||
- | docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.11-management | + | docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:management-alpine |
</code> | </code> | ||
Sor 60: | Sor 60: | ||
</code> | </code> | ||
- | Let's create the consumer, and the create statistics: | + | Let's create the //quality_message_consumer.py// file, and the create statistics: |
+ | |||
+ | (do not forget to create it in an other terminal, and run //pip install pika// and set the proper IP in //pika.ConnectionParameters()// ) | ||
<code python> | <code python> | ||
Sor 67: | Sor 69: | ||
class QualityConsumer: | class QualityConsumer: | ||
def __init__(self): | def __init__(self): | ||
- | self.connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) | + | self.connection = pika.BlockingConnection(pika.ConnectionParameters('10.x.y.z')) |
self.channel = self.connection.channel() | self.channel = self.connection.channel() | ||
self.channel.queue_declare(queue='qualityQueue') | self.channel.queue_declare(queue='qualityQueue') | ||
Sor 108: | Sor 110: | ||
except KeyboardInterrupt: | except KeyboardInterrupt: | ||
consumer.close_connection() | consumer.close_connection() | ||
+ | </code> | ||
+ | |||
+ | The third components prints the statistics. Let's create an other instance (terminal) and create statistics_consumer.py | ||
+ | |||
+ | <code python> | ||
+ | import pika | ||
+ | |||
+ | # RabbitMQ settings | ||
+ | connection = pika.BlockingConnection(pika.ConnectionParameters('10.x.y.z')) | ||
+ | channel = connection.channel() | ||
+ | |||
+ | channel.queue_declare(queue='qualityStatistics') | ||
+ | |||
+ | def callback(ch, method, properties, body): | ||
+ | message = body.decode() | ||
+ | print(f'{message}') | ||
+ | ch.basic_ack(delivery_tag=method.delivery_tag) | ||
+ | |||
+ | channel.basic_consume(queue='qualityStatistics', on_message_callback=callback) | ||
+ | |||
+ | print('Waiting for quality statistics...') | ||
+ | channel.start_consuming() | ||
</code> | </code> | ||