Using JMS for long running processes?

Can someone point me to a tutorial or similar code where JMS is used by a web application to execute a multi-year background process? (instead of using threads), I am pretty familiar with JMS messaging concepts, but have never used JMS APIs or brokers (I look at learning Apache ActiveMQ)

I would like to be able to: send a message to the queue to start the process, check the status (progress) on this process at any time

Thanks!

+4
source share
2 answers

The real point of using JMS in your context is to run tasks asynchronously. This is called fire and forgets about the bonding layer. JMS has guaranteed delivery semantics, which means that after the message has been queued, it will certainly be there ... finally.

The idea is that you perform all the tasks that you need to perform, and if you have any tasks in the process that can be completed later, you put the message in a queue and then it will be executed. This allows you to reduce processing by a significant amount while someone is waiting for an answer.

Another advantage of JMS is that different parts of the system do not have to start at the same time. The message consuming part may not be available for maintenance while your front end is still running.

+2
source

The previous message is accurate from the model point of view for sending orders or requests to the queue asynchronously, and then they can be received later. However, in reality it does not address the issue of lengthy processes.

Regarding queues and topics, the advantage of constant queues is that if there are no consumers in the queue, messages will wait for consumption until a subscriber appears. In the topic, you need to create a long-term subscription to make sure that a consumer who is not connected will receive messages that are sent in his absence after reconnecting.

So how do you define a lengthy process? For a multi-step process, you usually use something like a workflow mechanism. There are options like a BPM tool or something like "Workflow OS." You can also make a home solution, which may look like an example below

1) There must be some definition of the workflow that defines the steps in the process. It can be a properties file or an XML file. 2) The web application puts a message in a queue or topic (pub / sub) indicating the process that should be performed (or you can have specific destinations for different processes) 3) MDB dispatcher selects the "order" from the queue with the status "NEW "and begins processing the first step. 4) As soon as the step is completed, the MDB places a new message in the queue indicating the process to be executed, and either the next step to be performed or the last step to be performed (depending on how deterministic you want this process to be was) 5) MDB picks up the message and sees that the process is "IN_PROGRESS". It either determines the next step that will be executed, or reads the step that will be performed further from the message (either the value of the JMS header, or inside the message, possibly in XML format) 6) Steps 4 and 5 are repeated until the process instance is completed

In this case, you will need an external view of the order information and the process instance. This will allow you to check the status of the request from your WebApp. Your order must be read and saved with an updated status after each step of the process so that WebApp can access status information.

A key component of this architecture is the MDB manager, which listens for messages and performs the next step in the process. When I worked with OS Workflow, this was one key thing that was missing. Thus, you can control the number of threads performing process steps by controlling the number of MDBs in the pool and consumers in the queue. In this architecture, I would recommend a topic queue for workflow steps. However, after each step of the process, you can post a message to a topic for subscribers to get updated status information.

With Java EE6 technologies, including JPA, you can easily create an XSD, create a POJO domain data model with JAXB, and use JPA to save. This year we conducted an online broadcast that covered JEE6 technologies, which are currently supported by WebLogic. Here are the repetitions: http://www.oracle.com/technetwork/middleware/weblogic/learnmore/weblogic-javaee6-webcasts-358613.html .

I am also interested in talking with you about your JBoss migration :) jeffrey.west@oracle.com

+1
source

All Articles