Java WorkflowOptions reference
Create a newWorkflowStub
in the Temporal Client code, call the instance of the Workflow, and set the Workflow options with the WorkflowOptions.Builder
class.
The following fields are available:
Option | Required | Type |
---|---|---|
WorkflowId | No (but recommended) | String |
TaskQueue | Yes | String |
WorkflowExecutionTimeout | No | Duration |
WorkflowRunTimeout | No | Duration |
WorkflowTaskTimeout | No | Duration |
WorkflowIdReusePolicy | No | WorkflowIdReusePolicy |
RetryOptions | No | RetryOptions |
CronSchedule | No | String |
Memo | No | string |
SearchAttributes | No | Map<String, Object> |
Id
Set the Workflow Id with the WorkflowStub
instance in the Client code using WorkflowOptions.Builder.setWorkflowId
.
- Type:
String
- Default: none
//create Workflow stub for YourWorkflowInterface
YourWorkflowInterface workflow1 =
WorkerGreet.greetclient.newWorkflowStub(
GreetWorkflowInterface.class,
WorkflowOptions.newBuilder()
// Set the Workflow Id
.setWorkflowId("YourWF")
.setTaskQueue(WorkerGreet.TASK_QUEUE)
.build());
TaskQueue
Set the Workflow Task Queue with the WorkflowStub
instance in the Client code using WorkflowOptions.Builder.setTaskQueue
.
- Type:
String
- Default: none
//create Workflow stub for YourWorkflowInterface
YourWorkflowInterface workflow1 =
WorkerGreet.greetclient.newWorkflowStub(
GreetWorkflowInterface.class,
WorkflowOptions.newBuilder()
.setWorkflowId("YourWF")
// Set the Task Queue
.setTaskQueue(WorkerGreet.TASK_QUEUE)
.build());
WorkflowExecutionTimeout
Set the Workflow Execution Timeout with the WorkflowStub
instance in the Client code using WorkflowOptions.Builder.setWorkflowExecutionTimeout
.
- Type:
time.Duration
- Default: Unlimited
//create Workflow stub for YourWorkflowInterface
YourWorkflowInterface workflow1 =
WorkerGreet.greetclient.newWorkflowStub(
GreetWorkflowInterface.class,
WorkflowOptions.newBuilder()
.setWorkflowId("YourWF")
.setTaskQueue(WorkerGreet.TASK_QUEUE)
// Set Workflow Execution Timeout duration
.setWorkflowExecutionTimeout(Duration.ofSeconds(10))
.build());
WorkflowRunTimeout
Set the Workflow Run Timeout with the WorkflowStub
instance in the Client code using WorkflowOptions.Builder.setWorkflowRunTimeout
.
- Type:
time.Duration
- Default: Same as WorkflowExecutionTimeout.
//create Workflow stub for YourWorkflowInterface
YourWorkflowInterface workflow1 =
WorkerGreet.greetclient.newWorkflowStub(
GreetWorkflowInterface.class,
WorkflowOptions.newBuilder()
.setWorkflowId("YourWF")
.setTaskQueue(WorkerGreet.TASK_QUEUE)
// Set Workflow Run Timeout duration
.setWorkflowRunTimeout(Duration.ofSeconds(10))
.build());
WorkflowTaskTimeout
Set the Workflow Task Timeout with the WorkflowStub
instance in the Client code using WorkflowOptions.Builder.setWorkflowTaskTimeout
.
- Type:
time.Duration
- Default: 10 seconds.
- Values: Maximum accepted value is 60 seconds.
//create Workflow stub for YourWorkflowInterface
YourWorkflowInterface workflow1 =
WorkerGreet.greetclient.newWorkflowStub(
GreetWorkflowInterface.class,
WorkflowOptions.newBuilder()
.setWorkflowId("YourWF")
.setTaskQueue(WorkerGreet.TASK_QUEUE)
// Set Workflow Task Timeout duration
.setWorkflowTaskTimeout(Duration.ofSeconds(10))
.build());
WorkflowIDReusePolicy
- Type:
WorkflowIdReusePolicy
- Default:
enums.AllowDuplicateFailedOnly
is the default value. It means that the Workflow can start a new run if the previous run failed, was canceled, or was terminated. - Values:
AllowDuplicate
allows a new run independently of the previous run closure status.RejectDuplicate
doesn't allow a new run independently of the previous run closure status.
```java
//create Workflow stub for GreetWorkflowInterface
GreetWorkflowInterface workflow1 =
WorkerGreet.greetclient.newWorkflowStub(
GreetWorkflowInterface.class,
WorkflowOptions.newBuilder()
.setWorkflowId("GreetWF")
.setTaskQueue(WorkerGreet.TASK_QUEUE)
// Set Workflow Id Reuse Policy
.setWorkflowIdReusePolicy(
WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE)
.build());
RetryOptions
Set Workflow Retry Options in the WorkflowStub
instance using WorkflowOptions.Builder.setWorkflowRetryOptions
.
- Type:
RetryOptions
- Default:
Null
which means no retries will be attempted.
//create Workflow stub for GreetWorkflowInterface
GreetWorkflowInterface workflow1 =
WorkerGreet.greetclient.newWorkflowStub(
GreetWorkflowInterface.class,
WorkflowOptions.newBuilder()
.setWorkflowId("GreetWF")
.setTaskQueue(WorkerGreet.TASK_QUEUE)
// Set Workflow Retry Options
.setRetryOptions(RetryOptions.newBuilder()
.build());
CronSchedule
Set the Cron Schedule with the WorkflowStub
instance in the Client code using WorkflowOptions.Builder.setCronSchedule
.
Setting setCronSchedule
changes the Workflow Execution into a Temporal Cron Job.
The default timezone for a Cron is UTC.
- Type:
String
- Default: None
//create Workflow stub for YourWorkflowInterface
YourWorkflowInterface workflow1 =
YourWorker.yourclient.newWorkflowStub(
YourWorkflowInterface.class,
WorkflowOptions.newBuilder()
.setWorkflowId("YourWF")
.setTaskQueue(YourWorker.TASK_QUEUE)
// Set Cron Schedule
.setCronSchedule("* * * * *")
.build());
For more details, see the Cron Sample
Memo
- Type:
String
- Default: None
//create Workflow stub for GreetWorkflowInterface
GreetWorkflowInterface workflow1 =
WorkerGreet.greetclient.newWorkflowStub(
GreetWorkflowInterface.class,
WorkflowOptions.newBuilder()
.setWorkflowId("GreetWF")
.setTaskQueue(WorkerGreet.TASK_QUEUE)
// Set Memo. You can set additional non-indexed info via Memo
.setMemo(ImmutableMap.of(
"memoKey", "memoValue"
))
.build());
SearchAttributes
Search Attributes are additional indexed information attributed to Workflow and used for search and visibility. These can be used in a query of List/Scan/Count Workflow APIs. The key and its value type must be registered on Temporal server side.
- Type:
Map<String, Object>
- Default: None
private static void parentWorkflow() {
ChildWorkflowOptions childworkflowOptions =
ChildWorkflowOptions.newBuilder()
// Set Search Attributes
.setSearchAttributes(ImmutableMap.of("MySearchAttributeNAme", "value"))
.build();
The following Java types are supported:
- String
- Long, Integer, Short, Byte
- Boolean
- Double
- OffsetDateTime
- Collection of the types in this list.