External Task: Waiting for callback best practice


#1

I have a service task that needs to make a rest call and wait for a callback.

There are two options available for me:

  1. Split the service task in two.
    A service task making the rest call and a receive task to be notified when I receive the callback.
  2. Keep it as a single unit of work.
    The rest call is made inside the execute method of the handler, but the complete method is not called.
    Since I don’t have the instances of the ExternalTask and ExternalTaskService, I have to save the id to DB and when the callback is received I retrieve the id and use the REST API call “complete” to finish the activity.

I’ve been told that this should be a single unit of work and this split is too low level to be included into the BPMN.

Do you know what would be considered best practice in this case?
Also, if you have a better approach please let me know.

Help is highly appreciated :slight_smile:


#2

Is this what you are looking for? https://github.com/camunda/camunda-bpm-examples/tree/master/servicetask/service-invocation-asynchronous

You could for example use a process variable as the identifier for matching the callback to the correct process instance.


#3

Hello Thorben,

Thank you for the reply.
In my case the Camunda engine runs on a separate service and the communication is done trough external tasks.
So I don’t think I can use the provided scenario.

I’m restricted to using the camunda external task client or REST calls.

Best regards,
Cosmin


#4

Hm, thanks for the clarification. Then the second approach you describe in your first post sounds perfectly reasonable to me.


#5

Both approaches from the first post work.
I just didn’t know which option would be the better one.

I have a hard time figuring out the granularity in the workflow.

For example in the first approach I have a higher granularity, but it simplifies the the code logic.
In the second approach I have less activities in the flow but I have to add extra logic in the code.