Completing a Service Task, implemented as JavaDelegate with a CallBack REST call

I have a Service Task implemented as a Java Delegate class, which means the service task is attached to a java class implementing org.camunda.bpm.engine.delegate.JavaDelegate class within the process engine service.

Can I complete this task from outside using some REST API? Think about User Task, which is started by the process engine, but someone from outside completes it using the REST API call.

Actually, I want to have a Java Delegate Class, which will call a REST API of another service. Now that microservice will perform the job (which is supposed by this Service Task) asynchronously.

I know if I just call this REST API in delegate class then that task will finish and move ahead in the process. But I want to stay within the task and want to wait unless that microservice callbacks to complete this Service Task.

In summary, I want to call a REST API within Java Delegate class implementation and then go in Waiting State, And then the Other microservice (which is called) will callback to complete the task. Is there any possible solution for this?

@Himanshu_Singh yes, you can inovke a rest api from the service task. As you said that API is asynchronous, and need to wait until the service responded back to the process engine. This you can achieve by having the Recieve Task followed by service task. So that once the microservice responds to that Recieve Task the execution token flows through further the path.

1 Like

@aravindhrs
Do you mean the Service Task will just end after making the call to the REST API,
And there will be another Task (Recieve Task hopefully a User Task) which will be completed by the outside microservice with a Complete API call?

Assuming this solution, how does the other microservice will know the task instance next to service task, which it needs to complete?

Am I missing something about Receive Task here?

Not necessarily to be user task, recieve task can work with message correlation via rest api.

Use the message name with correlation keys. No need to identify the task instance

ok, my bad.
I think You mean the ā€œReceive Taskā€ Type similar to ā€œUser Taskā€ and ā€œService Taskā€

image

I hope attaching it to next to a ā€œService Taskā€ will solve my problem.

Yeah correct. Recive task has ā€œwaiting stateā€, it waits until the corresponding message correlation received

ā†’ it waits until the corresponding message correlation received
How to send that message Using REST API?

Is the below REST API the correct one?
https://docs.camunda.org/manual/7.13/reference/rest/message/

a bit older version of the documentation but indeed you just need to correlate the message to the process instance that initiated the call. You can do that in multiple ways but I suppose the most common is to provide either process instance id or the unique business key in your call back message so Camunda can correctly correlate your message to the right process instance.

1 Like