From b2354509c28ea096ab145431218a9d730d69122d Mon Sep 17 00:00:00 2001 From: Spencer Judge Date: Mon, 1 Dec 2025 16:30:02 -0800 Subject: [PATCH] Inline Nexus workflow ID formatting --- .../nexus/handler/NexusServiceImpl.java | 17 +++++++++++------ .../handler/NexusServiceImpl.java | 17 +++++++++++------ .../handler/NexusServiceImpl.java | 18 ++++++++++-------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java b/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java index 2344f27ec..7182f5e77 100644 --- a/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java +++ b/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java @@ -7,6 +7,7 @@ import io.temporal.nexus.Nexus; import io.temporal.nexus.WorkflowRunOperation; import io.temporal.samples.nexus.service.NexusService; +import java.util.Locale; // To create a service implementation, annotate the class with @ServiceImpl and provide the // interface that the service implements. The service implementation class should have methods that @@ -40,14 +41,18 @@ public OperationHandler hello HelloHandlerWorkflow.class, // Workflow IDs should typically be business meaningful IDs and are used to // dedupe workflow starts. - // For this example, we're using the request ID allocated by Temporal when - // the - // caller workflow schedules - // the operation, this ID is guaranteed to be stable across retries of this - // operation. + // For this example, tie the workflow ID to the customer being greeted so + // that + // repeated operations for the same customer run on the same workflow. // // Task queue defaults to the task queue this operation is handled on. - WorkflowOptions.newBuilder().setWorkflowId(details.getRequestId()).build()) + WorkflowOptions.newBuilder() + .setWorkflowId( + String.format( + "hello-%s-%s", + input.getName(), + input.getLanguage().name().toLowerCase(Locale.ROOT))) + .build()) ::hello); } } diff --git a/core/src/main/java/io/temporal/samples/nexuscontextpropagation/handler/NexusServiceImpl.java b/core/src/main/java/io/temporal/samples/nexuscontextpropagation/handler/NexusServiceImpl.java index 4977ff0c0..91abd61ae 100644 --- a/core/src/main/java/io/temporal/samples/nexuscontextpropagation/handler/NexusServiceImpl.java +++ b/core/src/main/java/io/temporal/samples/nexuscontextpropagation/handler/NexusServiceImpl.java @@ -8,6 +8,7 @@ import io.temporal.nexus.WorkflowRunOperation; import io.temporal.samples.nexus.handler.HelloHandlerWorkflow; import io.temporal.samples.nexus.service.NexusService; +import java.util.Locale; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; @@ -52,14 +53,18 @@ public OperationHandler hello HelloHandlerWorkflow.class, // Workflow IDs should typically be business meaningful IDs and are used to // dedupe workflow starts. - // For this example, we're using the request ID allocated by Temporal when - // the - // caller workflow schedules - // the operation, this ID is guaranteed to be stable across retries of this - // operation. + // For this example, tie the workflow ID to the customer being greeted so + // that + // repeated operations for the same customer run on the same workflow. // // Task queue defaults to the task queue this operation is handled on. - WorkflowOptions.newBuilder().setWorkflowId(details.getRequestId()).build()) + WorkflowOptions.newBuilder() + .setWorkflowId( + String.format( + "hello-%s-%s", + input.getName(), + input.getLanguage().name().toLowerCase(Locale.ROOT))) + .build()) ::hello); } } diff --git a/core/src/main/java/io/temporal/samples/nexusmultipleargs/handler/NexusServiceImpl.java b/core/src/main/java/io/temporal/samples/nexusmultipleargs/handler/NexusServiceImpl.java index 20d55fed8..b75edd0de 100644 --- a/core/src/main/java/io/temporal/samples/nexusmultipleargs/handler/NexusServiceImpl.java +++ b/core/src/main/java/io/temporal/samples/nexusmultipleargs/handler/NexusServiceImpl.java @@ -8,6 +8,7 @@ import io.temporal.nexus.WorkflowHandle; import io.temporal.nexus.WorkflowRunOperation; import io.temporal.samples.nexus.service.NexusService; +import java.util.Locale; // To create a service implementation, annotate the class with @ServiceImpl and provide the // interface that the service implements. The service implementation class should have methods that @@ -41,17 +42,18 @@ public OperationHandler hello // Workflow IDs should typically be business meaningful IDs and are used // to // dedupe workflow starts. - // For this example, we're using the request ID allocated by Temporal - // when - // the - // caller workflow schedules - // the operation, this ID is guaranteed to be stable across retries of - // this - // operation. + // For this example, tie the workflow ID to the customer being greeted + // so + // that + // repeated operations for the same customer run on the same workflow. // // Task queue defaults to the task queue this operation is handled on. WorkflowOptions.newBuilder() - .setWorkflowId(details.getRequestId()) + .setWorkflowId( + String.format( + "hello-%s-%s", + input.getName(), + input.getLanguage().name().toLowerCase(Locale.ROOT))) .build()) ::hello, input.getName(),