Async task execution & process state flush

In our application all service tasks are implemented as described here ( On execute method we send message to massage broker with the current executionId, and when we receive response we call runtime.signal with the same executionId.
The problem is, that some times remote service may send a response before process is flushed to database. So when the signal method is called camunda throws exception - no execution with this id.
So my question is how to send message after camunda saves the state of execution to the database.

For now I see only one solution: save message for remote service in some variable (thread local), create command interceptor and inside after next.execute(command) send this message to broker.

1 Like

Your solution looks fine. There is also an internal concept called transaction listener that you could use: Flush sql statements from cache to DB before calling a procedure. Be aware that once committed, the process will no longer roll back in case the message cannot be handed to the broker.

Another approach could be transaction integration, i.e. let the message broker and camunda share an XA transaction. This is rather heavy weight and depends on if the broker supports it, but might avoid some consistency problems.