tanszek:oktatas:iss_t:rabbitmq
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tanszek:oktatas:iss_t:rabbitmq [2024/04/22 08:13] – knehez | tanszek:oktatas:iss_t:rabbitmq [2024/04/22 08:49] (current) – knehez | ||
---|---|---|---|
Line 3: | Line 3: | ||
We send states to a message queue named ' | We send states to a message queue named ' | ||
- | - The first client | + | - The first component |
- | - Create a component that reads and collects the ' | + | - Create a component that reads and collects the '**GOOD**', '**EXCELLENT**', and '**WRONG**' messages from the qualityQueue queue. After receiving 10 identical messages, it sends a message to the '**qualityStatistics**' queue indicating that it has processed 10 messages of a certain quality. |
- | - Create a second | + | - Create a second |
< | < | ||
Line 41: | Line 41: | ||
</ | </ | ||
- | After running the command above, the RabbitMQ management console will be accessible on port 15672, using the credentials guest/ | + | After running the command above, the **RabbitMQ** management console will be accessible on port **15672**, using the credentials |
Create another terminal and execute the following command: | Create another terminal and execute the following command: | ||
Line 49: | Line 49: | ||
</ | </ | ||
- | This command installs the pika module, which provides the connection to RabbitMQ. | + | This command installs the pika module, which provides the connection to **RabbitMQ**. |
Create the // | Create the // | ||
Line 55: | Line 55: | ||
Use the appropriate IP address in the // | Use the appropriate IP address in the // | ||
- | <code python> | + | <sxh python> |
import pika | import pika | ||
import random | import random | ||
Line 83: | Line 83: | ||
except KeyboardInterrupt: | except KeyboardInterrupt: | ||
sender.close_connection() | sender.close_connection() | ||
- | </code> | + | </sxh> |
Let's create the // | Let's create the // | ||
Line 89: | Line 89: | ||
(do not forget to create it in an other terminal, and run //pip install pika// and set the proper IP in // | (do not forget to create it in an other terminal, and run //pip install pika// and set the proper IP in // | ||
- | <code python> | + | <sxh python> |
import pika | import pika | ||
Line 135: | Line 135: | ||
except KeyboardInterrupt: | except KeyboardInterrupt: | ||
consumer.close_connection() | consumer.close_connection() | ||
- | </code> | + | </sxh> |
The third components prints the statistics. Let's create an other instance (terminal) and create statistics_consumer.py | The third components prints the statistics. Let's create an other instance (terminal) and create statistics_consumer.py | ||
- | <code python> | + | <sxh python> |
import pika | import pika | ||
Line 150: | Line 150: | ||
def callback(ch, | def callback(ch, | ||
message = body.decode() | message = body.decode() | ||
+ | print(' | ||
print(f' | print(f' | ||
ch.basic_ack(delivery_tag=method.delivery_tag) | ch.basic_ack(delivery_tag=method.delivery_tag) | ||
Line 157: | Line 158: | ||
print(' | print(' | ||
channel.start_consuming() | channel.start_consuming() | ||
- | </code> | + | </sxh> |
tanszek/oktatas/iss_t/rabbitmq.1713773609.txt.gz · Last modified: 2024/04/22 08:13 by knehez