RabbitMQ Lab — VLibTour Group communication system with authentication
Introduction to the step
This page/step is about the use cases that are presented in Section 2.3 of the micro-project. The architectural entities that are concerned are the group communication system and the tourist application that are presented in Section 4 of the same document.
In this step/page, we add authentication to the group communication system that we have developed in the previous page.
Foreword
This page does not contain a definite step by step description of how to design the group communication of the micro-project. The description is not exhaustive: We only provide essential clues for a possible architecting of the AMQP infrastructure.
Group communication system in a dedicated virtual host and with authentication
Objectives: Up to now, all the tourist applications use the same broker (and the same host). If a tourist is informed, by whatever means, about the name of a group, the name of the tour, and the identifier of the user that has created the group, there is nothing in the system that prevents that tourist application to create a binding to the exchange of the group communication system of this specific visit. This is why we propose to use the concept of virtual host with access control in order to keep communication private to the group.
Learning phase
Before starting the refactoring for adding privacy concerns to the group communication systems, read the documentation page on the AMQP concept of virtual host, and then the section User Management of the rabbitmqctl command manual.
As an example, try the following sequence of commands in a terminal:
AMQP architecture of the system
The only difference with the previous figure of the architecture of the group communicaton system is that all the AMQP elements (exchange and queues) are in a dedicated virtual host. Since identifiers must be unique in a virtual host, we have also somewhat simplified the names of the exchange, of the queues, and of the binding keys.
This is the final architecture that we propose for a group communication system of a visit—i.e. a group of tourists in a visit. This architecture is going to be built by the lobby room server, which is going to be the subject of the next step. In the sequel of this page, we prepare class VLibTourGroupCommunicationSystemProxy with access control to an AMQP virtual host.
Additional design elements
There exist two ways to open a channel to a broker:
- Create a ConnectionFactory, set the host by calling ConnectionFactory::setHost, etc., open the connection by calling ConnectionFactory::newConnection, and create the channel by calling Connection::createChannel. This is the approach that we have used up to now;
- Create a ConnectionFactory, set a URL by calling ConnectionFactory::setUri, open the connection by calling ConnectionFactory::newConnection, and create the channel by calling Connection::createChannel. Compared to the previous approach, all the configuration parameters are set via the URI—i.e. one method call that replaces "ConnectionFactory::setHost, etc.".
In the next step, the URI that is going to be returned to the client by a call to createGroupAndJoinIt on the lobby room server will be of the form "amqp://userName:password@hostName:portNumber/virtualHost". Considering that a connection factory is created (see variable factory in the following assignment statement), the URI that is going to be returned by the lobby room to the tourist application will be of the form:
On the client side, the tourist application can use the URL for setting the configuration of the connection factory: e.g. the two instructions "ConnectionFactory factory = new ConnectionFactory();", and "factory.setHost("localhost");" will be replaced by the following instructions:
These two instructions are the easiest way to manage access control on the client side—i.e. no calls to ConnectionFactory::setVirtualHost, ConnectionFactory::setUserName, ConnectionFactory::setPassword, etc.
Adaptation of class VLibTourGroupCommunicationSystemProxy
Adapt the code of the proxy class in order to use a virtual host and add access control: The argument for connecting to RabbitMQ is going to be a URI.
Adapt also your JUnit classes, and perhaps shell scripts. Use some rabbitmqctl commands to create the users and to set their permissions.