Global task listener gets called before task is persistent

Hi all

We use Camunda global task listener by overriding “TaskListener getTaskListener()” method and it works create. But we have problem with that the task create events are created before the task object is actually commited? to the database.

The problem is that the task create event is sent to rabitmq and another system immediately makes rest request to get that task and usually the request fails with error: “org.camunda.bpm.engine.rest.exception.InvalidRequestException: No matching task with id XYZ”, probably because the task is not in the database yet. After waiting a second the task is there.

Note that we use cluster mode but this probably does not matter.

Is there some elegant solution to check if the task is actually commited in the database before sending the event out? I can come up with some ugly solutions, but I would not like for example to poll the database internally for the task.

Please let me know if I did not explain the problem good enough or you need some more information.
Thank you for your help!

Can anyone help? :smiley:

Hi,

I see three options:

  1. You configure rabbitmq and Camunda such that they share a transaction, so the message only shows up in the queue as soon as the overall transaction is committed. This would make both actions essentially atomic, eliminating a couple of other error sources (e.g. what if the message gets published but the Camunda transaction rolls back?).
  2. You implement retries in the code that reacts to the message.
  3. You implement a transaction listener as outlined here: Why can't I see the end event during a process instance end event listener?. This allows you to run code when the Camunda transaction has been committed. It is internal API and therefore not guaranteed to be stable.

Cheers,
Thorben