Testing

Let's build and run the server and worker of the application. You should start a container with a RabbitMQ instance, as we did in this chapter in the Bootstrap message broker for testing section. Then, use cargo build to build all the parts.

When compilation has finished, start a server instance:

RUST_LOG=rabbit_actix_server=debug ./target/debug/rabbit-actix-server

Also, start a worker instance with the following command:

RUST_LOG=rabbit_actix_worker=debug ./target/debug/rabbit-actix-worker

When both parts have started, you can explore RabbitMQ with the rabbitmqctl command and explore your queues:

docker exec -it test-rabbit rabbitmqctl list_queues

It prints both the queues that were created by the actors:

Timeout: 60.0 seconds ...
Listing queues for vhost / ...
responses 0
requests 0

If you want to see all connected consumers, you can do that with the following command:

docker exec -it test-rabbit rabbitmqctl list_consumers

It prints responses-consumer, which represents a server instance, and requests-consumer, which represents a worker instance:

Listing consumers on vhost / ...
responses <[email protected]> responses-consumer true 0 []
requests <[email protected]> requests-consumer true 0 []

Now that everything is connected to RabbitMQ, we can open http://localhost:8080/tasks in a browser. You will see an empty table and a form to upload a QR code. Choose a file and upload it using the form. It will refresh the page and you will see your task in progress:

 

If the worker works properly and if you refresh the page after short period of time, you will see the decoded QR code:

As you can see, the server and worker interact with a message that was delivered by RabbitMQ.

Let's discuss the benefits and drawbacks of this solution.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.123.73