User Tools

Site Tools


tanszek:oktatas:iss_t:rabbitmq

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tanszek:oktatas:iss_t:rabbitmq [2024/04/22 08:13] kneheztanszek:oktatas:iss_t:rabbitmq [2024/04/22 08:49] (current) knehez
Line 3: Line 3:
 We send states to a message queue named 'qualityQueue', which stores simple status messages of a quality assurance system. Create a multi-component application that communicates with the message queue through two clients in the following way: We send states to a message queue named 'qualityQueue', which stores simple status messages of a quality assurance system. Create a multi-component application that communicates with the message queue through two clients in the following way:
  
-  - The first client connects to the sensor placed on the measuring machine and randomly sends GOOD, EXCELLENT, and WRONG messages to the 'qualityQueue' message queue every second. +  - The first component connects to the sensor placed on the measuring machine and randomly sends **GOOD****EXCELLENT**, and **WRONG** messages to the '**qualityQueue**' message queue every second. 
-  - 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 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 client that reads the statistics from the 'qualityStatistics' queue and prints to the console, for example, '10 'WRONG' messages has been processed'.+  - Create a second component that reads the statistics from the '**qualityStatistics**' queue and prints to the console, for example, '10 'WRONG' messages has been processed'.
  
 <mermaid> <mermaid>
Line 41: Line 41:
 </code> </code>
  
-After running the command above, the RabbitMQ management console will be accessible on port 15672, using the credentials guest/guest. In the left-side menu, you can find the internal IP address (10.x.y.z) of node1, which can be used in the clients and processors.+After running the command above, the **RabbitMQ** management console will be accessible on port **15672**, using the credentials //guest/guest//. In the left-side menu, you can find the internal IP address (**10.x.y.z**) of node1, which can be used in the clients and processors.
  
 Create another terminal and execute the following command: Create another terminal and execute the following command:
Line 49: Line 49:
 </code> </code>
  
-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 //quality_message_sender.py//: Create the //quality_message_sender.py//:
Line 55: Line 55:
 Use the appropriate IP address in the //init(self):// method. Use the appropriate IP address in the //init(self):// method.
  
-<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 //quality_message_consumer.py// file: Let's create the //quality_message_consumer.py// file:
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 //pika.ConnectionParameters()// ) (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>+<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, method, properties, body): def callback(ch, method, properties, body):
     message = body.decode()     message = body.decode()
 +    print('-----------------------------')
     print(f'{message}')     print(f'{message}')
     ch.basic_ack(delivery_tag=method.delivery_tag)     ch.basic_ack(delivery_tag=method.delivery_tag)
Line 157: Line 158:
 print('Waiting for quality statistics...') print('Waiting for quality statistics...')
 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