Create a job from Jms message receive

118 Views Asked by At

Using wildfly 15 and only JavaEE (no spring) I need to consume messages from a Jms queue, in order and create for every message a new job using Jbatch, in sequence, without job overlap.

For example:

JMS queue: --> msgC --> msgB --> msgA

Jbatch:

  • on receive msgC, create JobC, run jobC
  • wait for JobC to end, watching JMS queue, on receive msgB, create JobB, run JobB
  • wait for JobB to end, watching JMS queue, on receive msgA, create JobA, run JobB

It's possible to achieve this ?

1

There are 1 best solutions below

1
On

Processing messages in parallel or the right sequence is some standard behaviour in JMS clients and you can simply configure to do it right. That's why you have a queue. Just ensure you have only one message driven bean working on it, which should ensure you have one process and nothing running in parallel.

If you handover the task to the batch API, a different set of threads will process it, and now you need to manually ensure one job terminates before the next can start. So your message driven bean would have to poll and wait until the batch executed.

Why would you do this as it just makes your life more complicated? I believe you could still benefit from the easy orchestration of batch steps, the restart capability or some parallel execution which you would have to cover in your message driven bean yourself.