How to prevent a transaction rolling back on runtime exceptions

Hi!

I need to optionally correlatte a message to a particular process instance (so correlateAll doesn’t work).

But correlate throws MismatchingMessageCorrelationException which is a runtime exception and marks transaction for rollback because SpringTransactionInterceptor uses its own TransactionTemplete which is sensible for all exceptions.

What would be the best way to set up this optional correlate mechanism?

Regards,
Ilia Rodionov.

Instead of performing the correlation straight away, you could use the same criteria you already have and first perform a query for existing executions. The RuntimeService has, for instance:

createEventSubscriptionQuery().eventType("message").<some=other-criteria>.singleResult()

First check if there’s an execution expecting the message, then if there is, perform the correlation, either by re-specifying the criteria or by just pointing to the exact execution you got from the query.

2 Likes

Great! Thank you a lot!

you’re welcome :slight_smile: