RabbitMQ Lab — Tutorial
Introduction of RabbitMQ broker
Here follows some explanations about the commands to launch and control the RabbitMQ server; please refer to these short explanations when you read the tutorial steps:
-
The server is launched with the Docker command:
The port 5672 is the port for the access to the broker and the port 15672 is the port for the access to management plugin of the broker.$ docker run -itd --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.9-management
We use the container 3.9-management in order to include the management plugin. -
The container just launched includes also a shell command
(bash). Therefore, the server is controlled with
the Docker command:
The utilitary command rabbitmqctl is a shell script, with the following arguments:$ docker exec rabbitmq rabbitmqctl <args>
- "status": to display broker status information such as the running applications, RabbitMQ and Erlang versions, OS name, memory and file descriptor statistics,
- "stop": to stop the Erlang node on which the RabbitMQ broker is running,
- "reset": to return the RabbitMQ broker to its virgin state (to be done after stopping the RabbitMQ broker with stop-app),
- "stop-app": to stop the RabbitMQ application (the broker), leaving the Erlang node running,
- "start-app": to start the RabbitMQ application (the broker) on the Erlang node,
- "list_queues": to display queues details such their names.
- "list_exchanges": to display exchanges details such their names.
- "list_bindings": to display bindings details such the routing keys.
-
The RabbitMQ broker is stopped and the Docker container is
remove using the following commands:
$ docker stop rabbitmq $ docker rm rabbitmq
Follow the tutorial prepared by the RabbitMQ team
Get the source code of the tutorials
The source code of the tutorials is provided in Maven modules in the project csc-mw-examples on the platform https://gitlabens.imtbs-tsp.eu. If you cannot or do not want to use Git, the examples are also available in this archive. Then, you should have the following directories:
Before starting the tutorial, compile all the examples.
RabbitMQ tutorial, step 1 (producer, consumer, and queue)
Move to the directory RabbitMQ-Tutorial-Step1. Learn the first set of AMQP concepts (producer, consumer, queue) with the corresponding RabbitMQ tutorial page. At the end of your reading of the tutorial page, you can execute the example as follows:
The code of the example is in the directory src/main/java/eu/telecomsudparis/rabbitmq/tutorial and the code of the test is in the directory src/test/java/eu/telecomsudparis/rabbitmq/tutorial. You can also import the Maven project in your favourite JAVA IDE, e.g. Eclipse, for browsing the code of the example.
Finally, comment the last two lines of the shell script run.sh and execute again the script. Let us now observe by executing the command "rabbitmqctl list_queues" that the queue hello that has been created still exists in the server even if there is no more producer or consumer. This is why we preventively reset the server. In the next steps, we could have not remove it and it will not disappear unless you stop and restart the server.
At your convenience, you can study the JUnit tests, compile and execute them with the command "mvn clean install". In case of problem "Connection refused" in the JUnit tests of the command "mvn clean install", check that you have activated the plugin rabbitmq_management with the command rabbitmq-plugins --offline enable rabbitmq_management.
RabbitMQ tutorial, step 2 (round-robing dispatching, durable message and message acknowledgment, message durability with durable queue and persistent message, fair dispatching with a prefetch countproducer, consumer, and queue)
Move to the directory RabbitMQ-Tutorial-Step2. Learn the next set of AMQP concepts (round-robing dispatching, durable message and message acknowledgment, message durability with durable queue and persistent message, fair dispatching with a prefetch countproducer, consumer, and queue) with the corresponding RabbitMQ tutorial page. At the end of your reading of the tutorial page, you can execute the example as follows:
The code of the example is in the directory src/main/java/eu/telecomsudparis/rabbitmq/tutorial and the code of the test is in the directory src/test/java/eu/telecomsudparis/rabbitmq/tutorial. You can also import the Maven project in your favourite JAVA IDE, e.g. Eclipse, for browsing the code of the example.
RabbitMQ tutorial, step 3 (exchange [of type fanout], binding, and temporary queue)
Move to the directory RabbitMQ-Tutorial-Step3. Learn the next set of AMQP concepts (exchange [of type fanout], binding, and temporary queue) with the corresponding RabbitMQ tutorial page. At the end of your reading of the tutorial page, you can execute the example as follows:
The code of the example is in the directory src/main/java/eu/telecomsudparis/rabbitmq/tutorial and the code of the test is in the directory src/test/java/eu/telecomsudparis/rabbitmq/tutorial. You can also import the Maven project in your favourite JAVA IDE, e.g. Eclipse, for browsing the code of the example.
RabbitMQ, tutorial, step 4 (binding key, exchange of type direct, routing key)
Move to the directory RabbitMQ-Tutorial-Step4. Learn the next set of AMQP concepts (binding key, exchange of type direct, routing key) with the corresponding RabbitMQ tutorial page. At the end of your reading of the tutorial page, you can execute the example as follows:
The code of the example is in the directory src/main/java/eu/telecomsudparis/rabbitmq/tutorial and the code of the test is in the directory src/test/java/eu/telecomsudparis/rabbitmq/tutorial. You can also import the Maven project in your favourite JAVA IDE, e.g. Eclipse, for browsing the code of the example.
RabbitMQ tutorial, step 5 (exchange of type topic, a word in a binding key, a star in a binding key, a hash in a binding key)
Move to the directory RabbitMQ-Tutorial-Step5. Learn the next set of AMQP concepts (exchange of type topic, a word in a binding key, a star in a binding key, a hash in a binding key) with the corresponding RabbitMQ tutorial page. At the end of your reading of the tutorial page, you can execute the example as follows:
The code of the example is in the directory src/main/java/eu/telecomsudparis/rabbitmq/tutorial and the code of the test is in the directory src/test/java/eu/telecomsudparis/rabbitmq/tutorial. You can also import the Maven project in your favourite JAVA IDE, e.g. Eclipse, for browsing the code of the example.
RabbitMQ tutorial, step 6 (How to realize RPC communication over topic-based DEBS with RabbitMQ)
Move to the the directory RabbitMQ-Tutorial-Step6. Learn the last set of AMQP concepts (How to realize RPC communication over topic-based DEBS with RabbitMQ) with the corresponding RabbitMQ tutorial page.
The code of the example is in the directory src/main/java/eu/telecomsudparis/rabbitmq/tutorial and the code of the test is in the directory src/test/java/eu/telecomsudparis/rabbitmq/tutorial. You can also import the Maven project in your favourite JAVA IDE, e.g. Eclipse, for browsing the code of the example.
Contrary to what is proposed into the tutorial page, in our code, we propose three different versions:
- using the JAVA client library with the standard AMQP calls (this is the version that is presented in the tutorial page),
- using the RabbitMQ-specific class StringRpcServer,
- using the RabbitMQ-specific classes of the package com.rabbitmq.tools.jsonrpc.
$Date: 2020-09-23 09:16:13 +0200 (mer. 23 sept. 2020) $