From db85804b77f8813de9947af423750b61038ee39e Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Mon, 17 Feb 2025 22:14:41 -0800 Subject: [PATCH 1/8] Update Nexus Sample for v1.28.0 --- .../nexus/caller/HelloCallerWorkflowImpl.java | 2 +- .../nexus/handler/NexusServiceImpl.java | 46 ++++++++++--------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/io/temporal/samples/nexus/caller/HelloCallerWorkflowImpl.java b/core/src/main/java/io/temporal/samples/nexus/caller/HelloCallerWorkflowImpl.java index dcc8d1a04..5b9048d60 100644 --- a/core/src/main/java/io/temporal/samples/nexus/caller/HelloCallerWorkflowImpl.java +++ b/core/src/main/java/io/temporal/samples/nexus/caller/HelloCallerWorkflowImpl.java @@ -43,7 +43,7 @@ public String hello(String message, NexusService.Language language) { Workflow.startNexusOperation( nexusService::hello, new NexusService.HelloInput(message, language)); // Optionally wait for the operation to be started. NexusOperationExecution will contain the - // operation ID in case this operation is asynchronous. + // operation token in case this operation is asynchronous. handle.getExecution().get(); return handle.getResult().get().getMessage(); } 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 4d6cb3cad..e65df3df9 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 @@ -23,7 +23,8 @@ import io.nexusrpc.handler.OperationImpl; import io.nexusrpc.handler.ServiceImpl; import io.temporal.client.WorkflowOptions; -import io.temporal.nexus.WorkflowClientOperationHandlers; +import io.temporal.nexus.Nexus; +import io.temporal.nexus.WorkflowRunOperation; import io.temporal.samples.nexus.service.NexusService; // To create a service implementation, annotate the class with @ServiceImpl and provide the @@ -34,32 +35,35 @@ public class NexusServiceImpl { @OperationImpl public OperationHandler echo() { // WorkflowClientOperationHandlers.sync is a meant for exposing simple RPC handlers. - return WorkflowClientOperationHandlers.sync( - // The method is provided with an SDK client that can be used for arbitrary calls such as - // signaling, querying, - // and listing workflows but implementations are free to make arbitrary calls to other - // services or databases, or + return OperationHandler.sync( + // The method is for to make arbitrary short calls to other services or databases, or // perform simple computations such as this one. - (ctx, details, client, input) -> new NexusService.EchoOutput(input.getMessage())); + // Users can also access a client by calling + // Nexus.getOperationContext().getWorkflowClient(ctx) to mae arbitrary calls such as + // signaling, querying, or listing workflows. + (ctx, details, input) -> new NexusService.EchoOutput(input.getMessage())); } @OperationImpl public OperationHandler hello() { - // Use the WorkflowClientOperationHandlers.fromWorkflowMethod constructor, which is the easiest + // Use the WorkflowRunOperation.fromWorkflowMethod constructor, which is the easiest // way to expose a workflow as an operation. - return WorkflowClientOperationHandlers.fromWorkflowMethod( - (ctx, details, client, input) -> - client.newWorkflowStub( - 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. - // - // Task queue defaults to the task queue this operation is handled on. - WorkflowOptions.newBuilder().setWorkflowId(details.getRequestId()).build()) + return WorkflowRunOperation.fromWorkflowMethod( + (ctx, details, input) -> + Nexus.getOperationContext() + .getWorkflowClient() + .newWorkflowStub( + 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. + // + // Task queue defaults to the task queue this operation is handled on. + WorkflowOptions.newBuilder().setWorkflowId(details.getRequestId()).build()) ::hello); } } From ddc53ba12ed1af18211bb5ac27308adfbd139647 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Mon, 17 Feb 2025 22:17:21 -0800 Subject: [PATCH 2/8] fix typo --- .../temporal/samples/nexus/handler/NexusServiceImpl.java | 7 +++---- 1 file changed, 3 insertions(+), 4 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 e65df3df9..de967848c 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 @@ -34,12 +34,11 @@ public class NexusServiceImpl { @OperationImpl public OperationHandler echo() { - // WorkflowClientOperationHandlers.sync is a meant for exposing simple RPC handlers. + // OperationHandler.sync is a meant for exposing simple RPC handlers. return OperationHandler.sync( // The method is for to make arbitrary short calls to other services or databases, or - // perform simple computations such as this one. - // Users can also access a client by calling - // Nexus.getOperationContext().getWorkflowClient(ctx) to mae arbitrary calls such as + // perform simple computations such as this one. Users can also access a workflow client by calling + // Nexus.getOperationContext().getWorkflowClient(ctx) to make arbitrary calls such as // signaling, querying, or listing workflows. (ctx, details, input) -> new NexusService.EchoOutput(input.getMessage())); } From d53edfbff3d2fdfc156704687e11f9c9266f04c6 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Tue, 18 Feb 2025 21:43:13 -0800 Subject: [PATCH 3/8] Small updates --- core/src/main/java/io/temporal/samples/nexus/README.MD | 4 ++-- .../io/temporal/samples/nexus/handler/NexusServiceImpl.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/io/temporal/samples/nexus/README.MD b/core/src/main/java/io/temporal/samples/nexus/README.MD index 526d3d486..f2feacaa1 100644 --- a/core/src/main/java/io/temporal/samples/nexus/README.MD +++ b/core/src/main/java/io/temporal/samples/nexus/README.MD @@ -24,7 +24,7 @@ This sample shows how to use Temporal for authoring a Nexus service and call it site](https://learn.temporal.io/getting_started/go/dev_environment/#set-up-a-local-temporal-service-for-development-with-temporal-cli) to install Temporal CLI. -> NOTE: Required version is at least v1.1.0. +> NOTE: Required version is at least v1.2.0. ### Spin up environment @@ -33,7 +33,7 @@ This sample shows how to use Temporal for authoring a Nexus service and call it > HTTP port is required for Nexus communications ``` -temporal server start-dev --http-port 7243 --dynamic-config-value system.enableNexus=true +temporal server start-dev --http-port 7243 ``` ### Initialize environment 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 de967848c..df57c743c 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 @@ -37,7 +37,8 @@ public OperationHandler echo() // OperationHandler.sync is a meant for exposing simple RPC handlers. return OperationHandler.sync( // The method is for to make arbitrary short calls to other services or databases, or - // perform simple computations such as this one. Users can also access a workflow client by calling + // perform simple computations such as this one. Users can also access a workflow client by + // calling // Nexus.getOperationContext().getWorkflowClient(ctx) to make arbitrary calls such as // signaling, querying, or listing workflows. (ctx, details, input) -> new NexusService.EchoOutput(input.getMessage())); From 6b9d446c1528eb029bc25e82042ce08d4ca8d9dc Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Tue, 18 Feb 2025 22:53:40 -0800 Subject: [PATCH 4/8] Refactor start workflow code --- .../samples/nexus/caller/CallerStarter.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/io/temporal/samples/nexus/caller/CallerStarter.java b/core/src/main/java/io/temporal/samples/nexus/caller/CallerStarter.java index 23dd0f5ec..5c65df949 100644 --- a/core/src/main/java/io/temporal/samples/nexus/caller/CallerStarter.java +++ b/core/src/main/java/io/temporal/samples/nexus/caller/CallerStarter.java @@ -19,9 +19,9 @@ package io.temporal.samples.nexus.caller; +import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; -import io.temporal.client.WorkflowStub; import io.temporal.samples.nexus.options.ClientOptions; import io.temporal.samples.nexus.service.NexusService; import org.slf4j.Logger; @@ -37,17 +37,19 @@ public static void main(String[] args) { WorkflowOptions.newBuilder().setTaskQueue(CallerWorker.DEFAULT_TASK_QUEUE_NAME).build(); EchoCallerWorkflow echoWorkflow = client.newWorkflowStub(EchoCallerWorkflow.class, workflowOptions); - logger.info("Workflow result: {}", echoWorkflow.echo("Nexus Echo 👋")); + WorkflowExecution execution = WorkflowClient.start(echoWorkflow::echo, "Nexus Echo 👋"); logger.info( - "Started workflow workflowId: {} runId: {}", - WorkflowStub.fromTyped(echoWorkflow).getExecution().getWorkflowId(), - WorkflowStub.fromTyped(echoWorkflow).getExecution().getRunId()); + "Started EchoCallerWorkflow workflowId: {} runId: {}", + execution.getWorkflowId(), + execution.getRunId()); + logger.info("Workflow result: {}", echoWorkflow.echo("Nexus Echo 👋")); HelloCallerWorkflow helloWorkflow = client.newWorkflowStub(HelloCallerWorkflow.class, workflowOptions); - logger.info("Workflow result: {}", helloWorkflow.hello("Nexus", NexusService.Language.ES)); + execution = WorkflowClient.start(helloWorkflow::hello, "Nexus", NexusService.Language.EN); logger.info( - "Started workflow workflowId: {} runId: {}", - WorkflowStub.fromTyped(helloWorkflow).getExecution().getWorkflowId(), - WorkflowStub.fromTyped(helloWorkflow).getExecution().getRunId()); + "Started HelloCallerWorkflow workflowId: {} runId: {}", + execution.getWorkflowId(), + execution.getRunId()); + logger.info("Workflow result: {}", helloWorkflow.hello("Nexus", NexusService.Language.ES)); } } From 83f4d65c886c1290bd7c59c0a5c150e09a9add0c Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Fri, 21 Feb 2025 15:52:48 -0800 Subject: [PATCH 5/8] use the cli --- build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 92d13ca62..1cdb2ff92 100644 --- a/build.gradle +++ b/build.gradle @@ -28,12 +28,13 @@ subprojects { ext { otelVersion = '1.30.1' otelVersionAlpha = "${otelVersion}-alpha" - javaSDKVersion = '1.27.0' + javaSDKVersion = '1.23.0-SNAPSHOT' camelVersion = '3.22.1' jarVersion = '1.0.0' } repositories { + mavenLocal() maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } From 75e4b8fc60d095e47a043071ebef18acb0350e62 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Wed, 26 Feb 2025 11:18:01 -0800 Subject: [PATCH 6/8] Update Java SDK --- build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 1cdb2ff92..51b1a80e5 100644 --- a/build.gradle +++ b/build.gradle @@ -28,13 +28,12 @@ subprojects { ext { otelVersion = '1.30.1' otelVersionAlpha = "${otelVersion}-alpha" - javaSDKVersion = '1.23.0-SNAPSHOT' + javaSDKVersion = '1.28.0' camelVersion = '3.22.1' jarVersion = '1.0.0' } repositories { - mavenLocal() maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } From 05aaf971627d61b8cadaf0166e80028f7372df57 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Wed, 26 Feb 2025 11:19:35 -0800 Subject: [PATCH 7/8] respond to PR comments --- core/src/main/java/io/temporal/samples/nexus/README.MD | 4 ++-- .../io/temporal/samples/nexus/handler/NexusServiceImpl.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/io/temporal/samples/nexus/README.MD b/core/src/main/java/io/temporal/samples/nexus/README.MD index f2feacaa1..bb5375afc 100644 --- a/core/src/main/java/io/temporal/samples/nexus/README.MD +++ b/core/src/main/java/io/temporal/samples/nexus/README.MD @@ -24,7 +24,7 @@ This sample shows how to use Temporal for authoring a Nexus service and call it site](https://learn.temporal.io/getting_started/go/dev_environment/#set-up-a-local-temporal-service-for-development-with-temporal-cli) to install Temporal CLI. -> NOTE: Required version is at least v1.2.0. +> NOTE: Required version is at least v1.3.0. ### Spin up environment @@ -33,7 +33,7 @@ This sample shows how to use Temporal for authoring a Nexus service and call it > HTTP port is required for Nexus communications ``` -temporal server start-dev --http-port 7243 +temporal server start-dev ``` ### Initialize environment 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 df57c743c..d7fda2fd9 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 @@ -36,7 +36,7 @@ public class NexusServiceImpl { public OperationHandler echo() { // OperationHandler.sync is a meant for exposing simple RPC handlers. return OperationHandler.sync( - // The method is for to make arbitrary short calls to other services or databases, or + // The method is for making arbitrary short calls to other services or databases, or // perform simple computations such as this one. Users can also access a workflow client by // calling // Nexus.getOperationContext().getWorkflowClient(ctx) to make arbitrary calls such as From 179b0d2296f5f6cec2d40c5cc4b179b52a14374c Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Wed, 26 Feb 2025 11:24:02 -0800 Subject: [PATCH 8/8] update wording --- core/src/main/java/io/temporal/samples/nexus/README.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/io/temporal/samples/nexus/README.MD b/core/src/main/java/io/temporal/samples/nexus/README.MD index bb5375afc..9e848c6d8 100644 --- a/core/src/main/java/io/temporal/samples/nexus/README.MD +++ b/core/src/main/java/io/temporal/samples/nexus/README.MD @@ -24,7 +24,7 @@ This sample shows how to use Temporal for authoring a Nexus service and call it site](https://learn.temporal.io/getting_started/go/dev_environment/#set-up-a-local-temporal-service-for-development-with-temporal-cli) to install Temporal CLI. -> NOTE: Required version is at least v1.3.0. +> NOTE: he recommended version is at least v1.3.0. ### Spin up environment