Skip to content

Commit 306cb17

Browse files
Update Nexus sample for v1.28.0 (#716)
Update Nexus Sample for v1.28.0
1 parent 1b1a632 commit 306cb17

File tree

5 files changed

+42
-36
lines changed

5 files changed

+42
-36
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ subprojects {
2828
ext {
2929
otelVersion = '1.30.1'
3030
otelVersionAlpha = "${otelVersion}-alpha"
31-
javaSDKVersion = '1.27.0'
31+
javaSDKVersion = '1.28.0'
3232
camelVersion = '3.22.1'
3333
jarVersion = '1.0.0'
3434
}

core/src/main/java/io/temporal/samples/nexus/README.MD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This sample shows how to use Temporal for authoring a Nexus service and call it
2424
site](https://learn.temporal.io/getting_started/go/dev_environment/#set-up-a-local-temporal-service-for-development-with-temporal-cli)
2525
to install Temporal CLI.
2626

27-
> NOTE: Required version is at least v1.1.0.
27+
> NOTE: he recommended version is at least v1.3.0.
2828
2929
### Spin up environment
3030

@@ -33,7 +33,7 @@ This sample shows how to use Temporal for authoring a Nexus service and call it
3333
> HTTP port is required for Nexus communications
3434
3535
```
36-
temporal server start-dev --http-port 7243 --dynamic-config-value system.enableNexus=true
36+
temporal server start-dev
3737
```
3838

3939
### Initialize environment

core/src/main/java/io/temporal/samples/nexus/caller/CallerStarter.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
package io.temporal.samples.nexus.caller;
2121

22+
import io.temporal.api.common.v1.WorkflowExecution;
2223
import io.temporal.client.WorkflowClient;
2324
import io.temporal.client.WorkflowOptions;
24-
import io.temporal.client.WorkflowStub;
2525
import io.temporal.samples.nexus.options.ClientOptions;
2626
import io.temporal.samples.nexus.service.NexusService;
2727
import org.slf4j.Logger;
@@ -37,17 +37,19 @@ public static void main(String[] args) {
3737
WorkflowOptions.newBuilder().setTaskQueue(CallerWorker.DEFAULT_TASK_QUEUE_NAME).build();
3838
EchoCallerWorkflow echoWorkflow =
3939
client.newWorkflowStub(EchoCallerWorkflow.class, workflowOptions);
40-
logger.info("Workflow result: {}", echoWorkflow.echo("Nexus Echo 👋"));
40+
WorkflowExecution execution = WorkflowClient.start(echoWorkflow::echo, "Nexus Echo 👋");
4141
logger.info(
42-
"Started workflow workflowId: {} runId: {}",
43-
WorkflowStub.fromTyped(echoWorkflow).getExecution().getWorkflowId(),
44-
WorkflowStub.fromTyped(echoWorkflow).getExecution().getRunId());
42+
"Started EchoCallerWorkflow workflowId: {} runId: {}",
43+
execution.getWorkflowId(),
44+
execution.getRunId());
45+
logger.info("Workflow result: {}", echoWorkflow.echo("Nexus Echo 👋"));
4546
HelloCallerWorkflow helloWorkflow =
4647
client.newWorkflowStub(HelloCallerWorkflow.class, workflowOptions);
47-
logger.info("Workflow result: {}", helloWorkflow.hello("Nexus", NexusService.Language.ES));
48+
execution = WorkflowClient.start(helloWorkflow::hello, "Nexus", NexusService.Language.EN);
4849
logger.info(
49-
"Started workflow workflowId: {} runId: {}",
50-
WorkflowStub.fromTyped(helloWorkflow).getExecution().getWorkflowId(),
51-
WorkflowStub.fromTyped(helloWorkflow).getExecution().getRunId());
50+
"Started HelloCallerWorkflow workflowId: {} runId: {}",
51+
execution.getWorkflowId(),
52+
execution.getRunId());
53+
logger.info("Workflow result: {}", helloWorkflow.hello("Nexus", NexusService.Language.ES));
5254
}
5355
}

core/src/main/java/io/temporal/samples/nexus/caller/HelloCallerWorkflowImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public String hello(String message, NexusService.Language language) {
4343
Workflow.startNexusOperation(
4444
nexusService::hello, new NexusService.HelloInput(message, language));
4545
// Optionally wait for the operation to be started. NexusOperationExecution will contain the
46-
// operation ID in case this operation is asynchronous.
46+
// operation token in case this operation is asynchronous.
4747
handle.getExecution().get();
4848
return handle.getResult().get().getMessage();
4949
}

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
import io.nexusrpc.handler.OperationImpl;
2424
import io.nexusrpc.handler.ServiceImpl;
2525
import io.temporal.client.WorkflowOptions;
26-
import io.temporal.nexus.WorkflowClientOperationHandlers;
26+
import io.temporal.nexus.Nexus;
27+
import io.temporal.nexus.WorkflowRunOperation;
2728
import io.temporal.samples.nexus.service.NexusService;
2829

2930
// To create a service implementation, annotate the class with @ServiceImpl and provide the
@@ -33,33 +34,36 @@
3334
public class NexusServiceImpl {
3435
@OperationImpl
3536
public OperationHandler<NexusService.EchoInput, NexusService.EchoOutput> echo() {
36-
// WorkflowClientOperationHandlers.sync is a meant for exposing simple RPC handlers.
37-
return WorkflowClientOperationHandlers.sync(
38-
// The method is provided with an SDK client that can be used for arbitrary calls such as
39-
// signaling, querying,
40-
// and listing workflows but implementations are free to make arbitrary calls to other
41-
// services or databases, or
42-
// perform simple computations such as this one.
43-
(ctx, details, client, input) -> new NexusService.EchoOutput(input.getMessage()));
37+
// OperationHandler.sync is a meant for exposing simple RPC handlers.
38+
return OperationHandler.sync(
39+
// The method is for making arbitrary short calls to other services or databases, or
40+
// perform simple computations such as this one. Users can also access a workflow client by
41+
// calling
42+
// Nexus.getOperationContext().getWorkflowClient(ctx) to make arbitrary calls such as
43+
// signaling, querying, or listing workflows.
44+
(ctx, details, input) -> new NexusService.EchoOutput(input.getMessage()));
4445
}
4546

4647
@OperationImpl
4748
public OperationHandler<NexusService.HelloInput, NexusService.HelloOutput> hello() {
48-
// Use the WorkflowClientOperationHandlers.fromWorkflowMethod constructor, which is the easiest
49+
// Use the WorkflowRunOperation.fromWorkflowMethod constructor, which is the easiest
4950
// way to expose a workflow as an operation.
50-
return WorkflowClientOperationHandlers.fromWorkflowMethod(
51-
(ctx, details, client, input) ->
52-
client.newWorkflowStub(
53-
HelloHandlerWorkflow.class,
54-
// Workflow IDs should typically be business meaningful IDs and are used to
55-
// dedupe workflow starts.
56-
// For this example, we're using the request ID allocated by Temporal when the
57-
// caller workflow schedules
58-
// the operation, this ID is guaranteed to be stable across retries of this
59-
// operation.
60-
//
61-
// Task queue defaults to the task queue this operation is handled on.
62-
WorkflowOptions.newBuilder().setWorkflowId(details.getRequestId()).build())
51+
return WorkflowRunOperation.fromWorkflowMethod(
52+
(ctx, details, input) ->
53+
Nexus.getOperationContext()
54+
.getWorkflowClient()
55+
.newWorkflowStub(
56+
HelloHandlerWorkflow.class,
57+
// Workflow IDs should typically be business meaningful IDs and are used to
58+
// dedupe workflow starts.
59+
// For this example, we're using the request ID allocated by Temporal when
60+
// the
61+
// caller workflow schedules
62+
// the operation, this ID is guaranteed to be stable across retries of this
63+
// operation.
64+
//
65+
// Task queue defaults to the task queue this operation is handled on.
66+
WorkflowOptions.newBuilder().setWorkflowId(details.getRequestId()).build())
6367
::hello);
6468
}
6569
}

0 commit comments

Comments
 (0)