Introduction to Workflows
Temporal Workflows orchestrate your Activities.
They are resilient - they can run and keep running for years, even if the underlying infrastructure fails. If the application itself crashes, Temporal will automatically recreate its Workflow’s pre-failure state so it can continue right where it left off.
In our reimbursement example, if the network fails right after the withdrawal but before the deposit, Temporal recreates the Workflow Execution from its last known state and continues as if no failure ever occurred.
This Workflow orchestrates our two Activities.
import io.temporal.workflow.WorkflowInterface;
import io.temporal.workflow.WorkflowMethod;
@WorkflowInterface
public interface ReimbursementWorkflow {
@WorkflowMethod
String processReimbursement(String userId, double amount);
}
import io.temporal.workflow.Workflow;
public class ReimbursementWorkflowImpl implements ReimbursementWorkflow {
private final ReimbursementActivities activities = Workflow.newActivityStub(
ReimbursementActivities.class,
);
@Override
public String processReimbursement(String userId, double amount) {
activities.withdrawMoney(amount);
activities.depositMoney(amount);
return "Reimbursement of $" + amount + " for user " + userId + " processed successfully";
}
}