This repo contains the Java SDK for the Durable Task Framework as well as classes and annotations to support running Azure Durable Functions for Java. With this SDK, you can define, schedule, and manage durable orchestrations using ordinary Java code.
// *** Simple, fault-tolerant, sequential orchestration ***
String result = "";
result += ctx.callActivity("SayHello", "Tokyo", String.class).await() + ", ";
result += ctx.callActivity("SayHello", "London", String.class).await() + ", ";
result += ctx.callActivity("SayHello", "Seattle", String.class).await();
return result;
// Get the list of work-items to process
List<?> batch = ctx.callActivity("GetWorkBatch", List.class).await();
// Schedule each task to run in parallel
List<Task<Integer>> parallelTasks = batch.stream()
.map(item -> ctx.callActivity("ProcessItem", item, Integer.class))
.collect(Collectors.toList());
// Wait for all tasks to complete, then return the aggregated sum of the results
List<Integer> results = ctx.allOf(parallelTasks).await();
return results.stream().reduce(0, Integer::sum);
ApprovalInfo approvalInfo = ctx.getInput(ApprovalInfo.class);
ctx.callActivity("RequestApproval", approvalInfo).await();
Duration timeout = Duration.ofHours(72);
try {
// Wait for an approval. A TaskCanceledException will be thrown if the timeout expires.
boolean approved = ctx.waitForExternalEvent("ApprovalEvent", timeout, boolean.class).await();
approvalInfo.setApproved(approved);
ctx.callActivity("ProcessApproval", approvalInfo).await();
} catch (TaskCanceledException timeoutEx) {
ctx.callActivity("Escalate", approvalInfo).await();
}
JobInfo jobInfo = ctx.getInput(JobInfo.class);
String jobId = jobInfo.getJobId();
String status = ctx.callActivity("GetJobStatus", jobId, String.class).await();
if (status.equals("Completed")) {
// The job is done - we can exit now
ctx.callActivity("SendAlert", jobId).await();
} else {
// wait N minutes before doing the next poll
Duration pollingDelay = jobInfo.getPollingDelay();
ctx.createTimer(pollingDelay).await();
// restart from the beginning
ctx.continueAsNew(jobInfo);
}
return null;
The following packages are produced from this repo.
For information about how to get started with Durable Functions for Java, see the Azure Functions README.md content.
Download Details:
Author: Microsoft
Official Github: https://github.com/microsoft/durabletask-java
License: MIT