Professional Documents
Culture Documents
1
Producer
Producer project contains 4 packages: entities, serialization, servlet, and start. Besides
this, information regarding the web application(html page, correspondence between webpage
and servlet class) is kept in webapp directory.
In the first package, we keep the DVD class. A dvd is described by: a title, year of
production and selling price.
2
RabbitMQ - Publish/Subscribe
In this section I will present the Message Repository that is in between producer and
consumer. This part is provided for us by RabbitMQ service. There are several ways of
creating messaging applications using RabbitMQ, but I preferred to use Publish/Subscribe
method. With this model, the producer does not send the messages directly to a queue. The
producer can only send messages to an exchange. An exchange receives on one side
messages from producers and on the other side it pushes them to queues. The exchange must
know exactly what to do with a message it receives. Exchange type allows specifying to
which queues to send the messages: to one of them, to all, etc. I used the fanout exchange
type. It just broadcasts all messages it receives to all queues it knows. In my project I
implemented two queues, for two consumers.
First, we have to create a Connection, and the a Channel. On the channel we declare
the exchange, with a given name and a type. After this declarations, we can publish the
messages on the exchange. Finally, we have to close the channel and the connection.
On the consumer side, we create too a connection and a channel. We declare the same
exchange as for the producer. We declare a queue on that channel and we bind to it. Then, we
are ready to receive messages that come on that queue. The messages will be lost if no queue
is bound to the exchange. handleDelivery method is overwritten and it is used for handling
the incoming messages.
Consumer
Consumer project has 4 packages: entities, serialization, service and start. The first
two are the same for the producer. In the service package we have two classes that provided
the needed services: FileService, MailService.
In the start package we have the consumers that connect to the queues and receive a
DVD. One consumers sends the email, and the other one writes the data in a text file.
3
Deployment diagram