Skip to content

Commit b235450

Browse files
committed
Inline Nexus workflow ID formatting
1 parent 626bf03 commit b235450

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

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

Lines changed: 11 additions & 6 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.NexusService;
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
@@ -40,14 +41,18 @@ public OperationHandler<NexusService.HelloInput, NexusService.HelloOutput> hello
4041
HelloHandlerWorkflow.class,
4142
// Workflow IDs should typically be business meaningful IDs and are used to
4243
// dedupe workflow starts.
43-
// For this example, we're using the request ID allocated by Temporal when
44-
// the
45-
// caller workflow schedules
46-
// the operation, this ID is guaranteed to be stable across retries of this
47-
// operation.
44+
// For this example, tie the workflow ID to the customer being greeted so
45+
// that
46+
// repeated operations for the same customer run on the same workflow.
4847
//
4948
// Task queue defaults to the task queue this operation is handled on.
50-
WorkflowOptions.newBuilder().setWorkflowId(details.getRequestId()).build())
49+
WorkflowOptions.newBuilder()
50+
.setWorkflowId(
51+
String.format(
52+
"hello-%s-%s",
53+
input.getName(),
54+
input.getLanguage().name().toLowerCase(Locale.ROOT)))
55+
.build())
5156
::hello);
5257
}
5358
}

core/src/main/java/io/temporal/samples/nexuscontextpropagation/handler/NexusServiceImpl.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.NexusService;
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<NexusService.HelloInput, NexusService.HelloOutput> hello
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/NexusServiceImpl.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.NexusService;
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<NexusService.HelloInput, NexusService.HelloOutput> hello
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)