How to keep a service task alive until we get 200 from the external service?

We are using http-connector for service-task, is there a way to keep the task alive until we get 200 from the external service?

@Minisha_M, Service task will be in waiting state until the response is received when downstream service api invocation is made.

The service task won’t wait for the use cases like:

  • If the downstream api itself async

  • Request timeout for api invocation

Best practices:

  • It’s better to invoke the downstream service from either listener or delegates rather than using http-connector.

  • For long running tasks, external task workers are recommended to avoid timeouts and better scalability so that service task can wait as long as the task is executed.

<dependency>
      <groupId>org.camunda.bpm</groupId>
      <artifactId>camunda-external-task-client</artifactId>
      <version>1.3.1</version>
</dependency>

@Slf4j
@Component
public class ExternalTaskServiceWorker {

  @Autowired
  private Gson gsonParser;

  @Autowired
  private ExternalWorkerConfiguration externalWorkerConfiguration;

  @EventListener(ApplicationReadyEvent.class)
  public void handleExternalTasks() {
    log.info("Initialzing the ExternalTaskServiceWorker with configuration:{}", externalWorkerConfiguration);

    ExternalTaskClient externalTaskClient = ExternalTaskClient.create()
        .baseUrl(externalWorkerConfiguration.getBaseUrl())
        .addInterceptor(
            requestContext -> requestContext.addHeader("Authorization", externalWorkerConfiguration.getAuthorization()))
        .asyncResponseTimeout(1000).maxTasks(2).workerId(externalWorkerConfiguration.getWorkerId()).build();

    TopicSubscription topicSubscription = externalTaskClient.subscribe(externalWorkerConfiguration.getTopicName())
        .handler((externalTask, externalTaskService) -> {

          Order order = new Order("ORD12", "Electronics", "Gift", 2000.00);

          JsonValue orderValue = ClientValues.jsonValue(gsonParser.toJson(order));

          Map<String, Object> variables = new HashMap<>();
          variables.put("order", orderValue);

          externalTaskService.complete(externalTask, variables);

          log.info("ExternalTask {} with businessKey {} completed!!!", externalTask.getId(),
              externalTask.getBusinessKey());

        }).lockDuration(30000).open();

    log.info("ExternalTaskServiceWorker has subscribed to the topic {} sucessfully", topicSubscription.getTopicName());

  }

}