How to start a job in a durable way from a transaction in my existing business logic #5076
Unanswered
raoulvdberge
asked this question in
Q&A
Replies: 1 comment
-
|
#4958 kind of talks about my problem. How to start a job async in a durable way as part of my business transaction? Spring Batch doesn't seem to support this as it wants to manage its own transaction, even when just wanting to start the job. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello there,
I was wondering what the best way is to (durably) start a job asynchronously as part of my business transaction.
In other words, I want the main business transaction to rollback if the request to start a job fails.
The externalized event system from Spring Modulith ensures that I can trigger events that will not get lost if the main transaction fails somehow. I want something similar for Spring Batch, in which I do not want to lose the job if the main transaction fails somehow.
At first, I was trying to do this with the event publication registry from Spring Modulith, roughly:
What I expect from this code:
SubmissionUnfortunately this way of working gives an exception that I cannot start jobs from within another transaction (the
@ApplicationModuleListeneris an async transaction on its own). I understand why this happens as Spring Batch has to manage the transaction, but I'm struggling to understand how else to integrate this.I've read https://docs.spring.io/spring-batch/reference/6.0-SNAPSHOT/spring-batch-integration/launching-jobs-through-messages.html but it's unclear to me how the
JobLaunchRequestfrom Spring Batch Integration can tie into the externalized event system from Spring Modulith.Beta Was this translation helpful? Give feedback.
All reactions