Skip to content

Commit 4cc3fe0

Browse files
SushisourceVegetarianOrc
authored andcommitted
Inline Nexus workflow ID formatting
1 parent 0a4092d commit 4cc3fe0

3 files changed

Lines changed: 33 additions & 19 deletions

File tree

core/src/main/java/io/temporal/samples/nexus/handler/SampleNexusServiceImpl.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.temporal.nexus.Nexus;
88
import io.temporal.nexus.WorkflowRunOperation;
99
import io.temporal.samples.nexus.service.SampleNexusService;
10+
import java.util.Locale;
1011

1112
// To create a service implementation, annotate the class with @ServiceImpl and provide the
1213
// interface that the service implements. The service implementation class should have methods that
@@ -55,13 +56,19 @@ public OperationHandler<SampleNexusService.HelloInput, SampleNexusService.HelloO
5556
.newWorkflowStub(
5657
HelloHandlerWorkflow.class,
5758
// Workflow IDs should typically be business meaningful IDs and are used to
58-
// dedupe workflow starts. For this example, we're using the request ID
59-
// allocated by Temporal when the caller workflow schedules
60-
// the operation, this ID is guaranteed to be stable across retries of this
61-
// operation.
59+
// dedupe workflow starts.
60+
// For this example, tie the workflow ID to the customer being greeted so
61+
// that
62+
// repeated operations for the same customer run on the same workflow.
6263
//
6364
// Task queue defaults to the task queue this operation is handled on.
64-
WorkflowOptions.newBuilder().setWorkflowId(details.getRequestId()).build())
65+
WorkflowOptions.newBuilder()
66+
.setWorkflowId(
67+
String.format(
68+
"hello-%s-%s",
69+
input.getName(),
70+
input.getLanguage().name().toLowerCase(Locale.ROOT)))
71+
.build())
6572
::hello);
6673
}
6774
}

core/src/main/java/io/temporal/samples/nexuscontextpropagation/handler/SampleNexusServiceImpl.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.temporal.nexus.WorkflowRunOperation;
99
import io.temporal.samples.nexus.handler.HelloHandlerWorkflow;
1010
import io.temporal.samples.nexus.service.SampleNexusService;
11+
import java.util.Locale;
1112
import org.slf4j.Logger;
1213
import org.slf4j.LoggerFactory;
1314
import org.slf4j.MDC;
@@ -52,14 +53,18 @@ public OperationHandler<SampleNexusService.HelloInput, SampleNexusService.HelloO
5253
HelloHandlerWorkflow.class,
5354
// Workflow IDs should typically be business meaningful IDs and are used to
5455
// dedupe workflow starts.
55-
// For this example, we're using the request ID allocated by Temporal when
56-
// the
57-
// caller workflow schedules
58-
// the operation, this ID is guaranteed to be stable across retries of this
59-
// operation.
56+
// For this example, tie the workflow ID to the customer being greeted so
57+
// that
58+
// repeated operations for the same customer run on the same workflow.
6059
//
6160
// Task queue defaults to the task queue this operation is handled on.
62-
WorkflowOptions.newBuilder().setWorkflowId(details.getRequestId()).build())
61+
WorkflowOptions.newBuilder()
62+
.setWorkflowId(
63+
String.format(
64+
"hello-%s-%s",
65+
input.getName(),
66+
input.getLanguage().name().toLowerCase(Locale.ROOT)))
67+
.build())
6368
::hello);
6469
}
6570
}

core/src/main/java/io/temporal/samples/nexusmultipleargs/handler/SampleNexusServiceImpl.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.temporal.nexus.WorkflowHandle;
99
import io.temporal.nexus.WorkflowRunOperation;
1010
import io.temporal.samples.nexus.service.SampleNexusService;
11+
import java.util.Locale;
1112

1213
// To create a service implementation, annotate the class with @ServiceImpl and provide the
1314
// interface that the service implements. The service implementation class should have methods that
@@ -41,17 +42,18 @@ public OperationHandler<SampleNexusService.HelloInput, SampleNexusService.HelloO
4142
// Workflow IDs should typically be business meaningful IDs and are used
4243
// to
4344
// dedupe workflow starts.
44-
// For this example, we're using the request ID allocated by Temporal
45-
// when
46-
// the
47-
// caller workflow schedules
48-
// the operation, this ID is guaranteed to be stable across retries of
49-
// this
50-
// operation.
45+
// For this example, tie the workflow ID to the customer being greeted
46+
// so
47+
// that
48+
// repeated operations for the same customer run on the same workflow.
5149
//
5250
// Task queue defaults to the task queue this operation is handled on.
5351
WorkflowOptions.newBuilder()
54-
.setWorkflowId(details.getRequestId())
52+
.setWorkflowId(
53+
String.format(
54+
"hello-%s-%s",
55+
input.getName(),
56+
input.getLanguage().name().toLowerCase(Locale.ROOT)))
5557
.build())
5658
::hello,
5759
input.getName(),

0 commit comments

Comments
 (0)