Skip to main content

Step 2: Running Workflows from Code

Continuing from Step 1

So far, we have seen how to compose and run basic workflows from the UI. However, more commonly, we will be running the workflows from an application or service. Let’s learn how to do this from our applications. Orkes Conductor platform offers various SDKs in different languages for integration with applications or services.

View our documentation on Conductor Clients & SDKs to learn how to import the required dependencies in our applications.

Let's look at some code examples of how to trigger a workflow by its name. We have also linked the repository where this code sample is hosted. To test these ourselves, we can also clone them locally and try them out.

Complete source file on Github: .../service/WorkflowService.java

StartWorkflowRequest request = new StartWorkflowRequest();
request.setName("deposit_payment");
Map<String, Object> inputData = new HashMap<>();
inputData.put("amount", depositDetail.getAmount());
inputData.put("accountId", depositDetail.getAccountId());
request.setInput(inputData);

String workflowId = workflowClient.startWorkflow(request);
log.info("Workflow id: {}", workflowId);

As an example, we might invoke this method when an endpoint is called, such as this API call in Java.

Complete source file on Github: .../controller/BankingApiController.java
    @PostMapping(value = "/triggerDepositFlow", produces = "application/json")
public ResponseEntity<Map<String, Object>> triggerDepositFlow(@RequestBody DepositDetail depositDetail) {
log.info("Starting deposit flow for: {}", depositDetail);
return ResponseEntity.ok(workflowService.startDepositWorkflow(depositDetail));
}

In addition to triggering from code, we can also run them from:

  1. UI - using the Run Workflow feature
  2. Upon receiving an Event
  3. Upon receiving a Webhook
  4. At a Schedule - using the Scheduler