0

I've defined a JMSReader as part of my Spring Batch Job (spring Boot) and have disabled the automatic job triggering. My requirement is to kick the job off when a message is received. Does the JMSReader bean perform the JMS receiving as well or should I define a separate JMSReceiver class. If I've to define the JMSreceiver, how do I trigger the job (JobLauncher?? - Will all the auto-injections work if manully triggered?)

Surya
  • 11
  • 1

1 Answers1

0

The JmsItemReader is used to read actual data (items) from a Jms queue. So using it to launch jobs is not adequate.

What you are looking for is actually the JobLaunchingMessageHandler which can be configured to listen to JobLaunchRequests and launch jobs accordingly.

You can find more details and a code example in the Launching Batch Jobs through Messages section of the reference documentation.

Hope this helps.

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50
  • Thanks, I will try this out. But isn't there another way without using Spring Integration? Can I define a JMSReceiver class that will launch the job? ( i tried this and its not exactly working) – Surya Jan 18 '19 at 13:25
  • Yes that's possible with plain JMS. You can reuse `JobLaunchRequest` from Spring Batch or create your own request class with the job to launch and its parameters. The JMS listener can then extract these details and launch the job by calling a `JobLauncher`. – Mahmoud Ben Hassine Jan 18 '19 at 14:40