Search code examples
javaperlrabbitmqmessage-queuemom

RabbitMQ and Application Decoupling


I need to setup RabbitMQ in an attempt to redesign our architecture using asynchronous messaging.

Existing Application Flow:

  • JEE web application (via browser) creates a new thread.
  • This thread creates a new OS process to invoke a Perl script to do some processing.
  • Perl script writes its output in a file and the control comes back to the thread.
  • The thread then reads the output file and loads the results to the database.
  • The control passes to the servlet which displays the result to the UI.

All these are synchronous and time consuming and we need to convert this to asynchronous messaging communication.

Now, I am planning to break this down to the following different components but not sure if this would work with RabbitMQ:

Application Breakdown:

  • JEE Web Application which is the Producer for RabbitMQ
  • Separate the Perl Script in to its own application that supports RabbitMQ communication. This Perl client will consume the message, process it and places a new message in RabbitMQ for the next step
  • Separate the output file to database loader into its own Java application that suppors RabbitMQ communication. This would consume the message from the queue corresponding to the Perl client's message from the previous step.

This way, the output would be available in the database and the asynchronous flow would be completed.

  1. Is is possible to separate the applications this way compatible to RabbitMQ?
  2. Are there any better ways to do this?
  3. Please suggest some framework components for RabbitMQ and Perl

Appreciate your inputs with this.


Solution

  • Yes, you can do it that way. If it's not a hard work, I'll include the database load on the Perl step. This probably avoids to handle an intermediate file, but I don't know if it's a viable task on your project.

    In order to use RabbitMQ, I'll recommend you the AnyEvent::RabbitMQ CPAN module. As the documentation establishes, You can use AnyEvent::RabbitMQ to:

    • Declare and delete exchanges
    • Declare, delete, bind and unbind queues
    • Set QoS and confirm mode
    • Publish, consume, get, ack, recover and reject messages
    • Select, commit and rollback transactions