0

We are using the JMSOutboundGateway to send message and receive message using the reply channel within the JMSOutboundGateway. When we run multiple iterations of the same job using the same JMSOutboundGateway, it fails with this error "Message contained wrong job instance id [85] should have been [86]" ( org.springframework.batch.integration.chunk.ChunkMessageChannelItemWriter.getNextResult() ) .

This is due to same JMSOutBoundGateway instance being using when I run the second when the first job is still in progress.

Is there a way I can run parallel execution of the same job type ?

rockycres
  • 71
  • 8

1 Answers1

0

This is a known issue, see https://github.com/spring-projects/spring-batch/issues/1372 and https://github.com/spring-projects/spring-batch/issues/1096.

The workaround is to use a separate instance of the writer for each job to prevent sharing the same reply channel.

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50
  • I have tried chunk writer in prototype scope as well as in step scope, still it is giving the same error. ( scope="prototype" scope="step" ) – rockycres Aug 27 '21 at 07:58
  • I did not mean scoped beans (this won't work as mentioned in https://github.com/spring-projects/spring-batch/issues/1096 which I shared in the answer), but two separate beans, one for each job/step. – Mahmoud Ben Hassine Aug 27 '21 at 08:09
  • I am not facing this issue within multiple steps for a job. I am facing this issue when I submit JobA with parameters ( x,y ) while it is in progress, I am submitting Job B with same parameters. While both JobA and JobB in progress, it is mixing up results. If it is for two different steps of a same job, then I could have easily implemented as you said using 2 different beans. – rockycres Aug 27 '21 at 09:29
  • Any other workaround for this issue ? Running parallel execution of the same job is a common requirement. I wonder how people are using this. – rockycres Aug 29 '21 at 22:37
  • The workaround is to share nothing between jobs, each job has its own step and its own writer/reply channel. That way, nothing will be mixed. – Mahmoud Ben Hassine Aug 30 '21 at 07:56
  • we need to run same job in different input parameters in parallel. Only way is to achieve this is by instructing spring to give different object instances of writer/reply channel etc.. for that, we had to use either prototype scope or step scope, both are not working. Again, I don't have any issue in running two different jobs since I can use different beans for each job type. we are having issue only with running same job in parallel. – rockycres Aug 31 '21 at 04:58