diff --git a/build.gradle b/build.gradle index 92d13ca62..51b1a80e5 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ subprojects { ext { otelVersion = '1.30.1' otelVersionAlpha = "${otelVersion}-alpha" - javaSDKVersion = '1.27.0' + javaSDKVersion = '1.28.0' camelVersion = '3.22.1' jarVersion = '1.0.0' } 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..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.1.0. +> NOTE: he recommended 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 --dynamic-config-value system.enableNexus=true +temporal server start-dev ``` ### Initialize environment 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)); } } 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..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 @@ -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 @@ -33,33 +34,36 @@ 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 - // perform simple computations such as this one. - (ctx, details, client, input) -> new NexusService.EchoOutput(input.getMessage())); + // OperationHandler.sync is a meant for exposing simple RPC handlers. + return OperationHandler.sync( + // 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 + // 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); } }