Skip to content

Commit

Permalink
Merge pull request #15 from RichardAF8/main
Browse files Browse the repository at this point in the history
Tech Lab Collaborative Version
  • Loading branch information
Mopezen authored Feb 20, 2024
2 parents c1e8a3c + 7274c5b commit a28b1ab
Show file tree
Hide file tree
Showing 42 changed files with 478 additions and 210 deletions.
24 changes: 24 additions & 0 deletions Tech-Lab-On-Campus/Producer-And-Consumer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Problem Definition: ✨Producer And Consumer✨

## Instructions

In this section, you will collaborate with a partner to instantiate the producer and consumer classes. One person will focus on the producer section while the other works on the consumer section. Afterwards, you'll exchange solutions verbally or via GitHub. We highly recommend using GitHub for this purpose, working on the same fork, and pushing your solutions. GitHub is widely used across the tech industry. You can find a GitHub file in the resource folder to assist you with this.

Below are bullet points of the criteria:
- First ensure that each contributor is working from and has `cloned the same fork` of the BBIT-LEARNING-LABS repository.
- Second ensure that each contributor has been `added as a collaborator to the fork.`
- One person completes the `producer section.`
- One person completes the `consumer section.`
- Each contributor should then `git push` their solutions to the fork.
- Lastly, follow the `testing instructions below` to send and recieve a message to complete this section.


`IMPORTANT!!!` Please utlize the [Functions.md](../Resources/Functions.md) file as it contains almost all the functions you will need for this lab. Also, other helpful information can be found under the Resources folder for Python, Git, and RabbitMQ details.

## Testing
In order to verify that the consumer and producer class was properly instantiated, we will use the provided `consume.py`, and `publish.py` file from producer and consumer folder. Follow the below instructions:
1. In the terminal window, run the `consume.py` file from the consumer sectio using the python interpreter.
2. In another terminal window, run the `publish.py` file from the producer section using the python interpreter. This will publish a message using RabbitMQ.
3. Return to the first terminal window with the consumer running. "Success! Producer And Consumer Section Complete." should now be displayed on your terminal if you instantiated & implemented the consumer class correctly.
* Note that if you are developing from the terminal in your IDE, inside the second terminal window you will need to step into the rmq_lab Docker container in order to access the python enviroment. We do this by first running the `docker exec -it [containterName\containerID] /bin/bash` command. Using the `docker ps -a` command will show all the running docker containers and their associated I.D and names. Your command could be `docker exec -it tech-lab-on-campus-rmq_lab-1 /bin/bash` or `docker exec -it 8a785d10fd7e /bin/bash`

36 changes: 36 additions & 0 deletions Tech-Lab-On-Campus/Producer-And-Consumer/consumer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Problem Definition: ✨Consumer✨

## Instructions
Create a .py file that will contain a class that is setup to be a consumer in the RabbitMQ framework. This class will inherit from the mqConsumerInterface and consume and print a simple UTF-8 string message.

Below are bullet points of the criteria:
- In the `solution` directory, create a file named `consumer_sol.py`
- Write your code in the `consumer_sol.py` file
- Create a class named `mqConsumer`
- Your class should inherit from our mqConsumerInterface.
- Constructor: Save the three variables needed to instantiate the class.
- Constructor: Call the setupRMQConnection function.
- setupRMQConnection Function: Establish connection to the RabbitMQ service, declare a queue and exchange, bind the binding key to the queue on the exchange and finally set up a callback function for receiving messages
- onMessageCallback: Print the UTF-8 string message and then close the connection.
- startConsuming: Consumer should start listening for messages from the queue.


## Testing
In order to verify that the consumer class was properly instantiated, we will use the provided `consume.py`, file. Follow the below instructions:
1. Start consumer
* To test your implementation you can run `consume.py`. It will import your newly created class from the source file `consume_sol.py` in the `solution` directory.
2. Log Into the RabbitMQ website.
* The login URL for the management web application will be http://localhost:15672/
* Login username and password should be `guest`
3. Check Queue
* Click on tab `Queues and Streams`.
* Under this tab you should see your created Queue appropriately named `Tech Lab Queue`

![alt text](../../../data/Images/consumerQueue.jpeg)

4. Check Binding
* Click on the "Tech Lab Queue"
* You should see under `Bindings` that the Queue is bound to the exchange `Tech Lab Exchange` with the key `Tech Lab Key`

![alt text](../../../data/Images/consumerBinding.jpeg)

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import os
import sys

from consumer_sol import mqConsumer # pylint: disable=import-error
from solution.consumer_sol import mqConsumer # pylint: disable=import-error


def main() -> None:
consumer = mqConsumer(binding_key="Routing Key",exchange_name="Exchange Name",queue_name="Queue Name")
consumer = mqConsumer(binding_key="Tech Lab Key",exchange_name="Tech Lab Exchange",queue_name="Tech Lab Queue")
consumer.startConsuming()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ def setupRMQConnection(self) -> None:
def on_message_callback(
self, channel, method_frame, header_frame, body
) -> None:
# Acknowledge and print message
# Acknowledge message

#Print message

# Close channel and connection
pass

def startConsuming(self) -> None:
# Print " [*] Waiting for messages. To exit press CTRL+C"

# Start consuming messages
pass
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@
Create a ".py" file that will contain a class set up to be a producer in the RabbitMQ framework. This class will inherit from the mqProducerInterface and should publish a simple UTF-8 string message.

Below are bullet points of the criteria:
- Your class should be named mqProducer.
- In the `solution` directory, create a file named `producer_sol.py`
- Write your code in the `producer_sol.py` file
- Create a class named `mqProducer`
- Your class should inherit from our mqProducerInterface.
- The class name should be `mqProducer` & the source file should be called `producer_sol.py`
- Constructor: Save the two variables needed to instantiate the class.
- Constructor: Call the setupRMQConnection function.
- setupRMQConnection Function: Establish connection to the RabbitMQ service.
- publishOrder: Publish a simple UTF-8 string message from the parameter.

###### [Note: Utilize the following resource to help instantiate the Producer Class: [RabbitMQ Toturial](https://www.rabbitmq.com/tutorials/tutorial-one-python.html)]

## Testing
To test your producer class, we'll use Docker to set up a container running RabbitMQ. We'll then create a testing container where you can run the test code provided. To validate the messages are being sent, you'll utilize the RabbitMQ container's management web application.
1. Log Into the RabbitMQ website.
* The login URL for the management web application will be http://localhost:15672/
* Login username and password should be "guest"
3. Send your message
* To test your implementation you can run `publish.py`. It will import your newly created class from the source file `producer_sol.py`
* To test your implementation you can run `publish.py`. It will import your newly created class from the source file `producer_sol.py` in the `solution` directory.
4. Check Message Rates
* Return to the RabbitMQ website.
* Look Under the Overview Tab for message rates to verify that a message was sent. Your message rate should look like the image below.

![alt text](./message_rate.jpeg)
![alt text](../../../data/Images/message_rate.jpeg)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import sys

# Update the import to match the producer class file you created if it's different then the default
from producer_sol import mqProducer # pylint: disable=import-error
from solution.producer_sol import mqProducer # pylint: disable=import-error


def main() -> None:
producer = mqProducer(routing_key="Routing Key",exchange_name="Exchange Name")
producer.publishOrder("Hello World")
producer = mqProducer(routing_key="Tech Lab Key",exchange_name="Tech Lab Exchange")
producer.publishOrder("Success! Producer And Consumer Section Complete.")


if __name__ == "__main__":
Expand Down
Empty file.
Loading

0 comments on commit a28b1ab

Please sign in to comment.