Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/io/temporal/samples/nexus/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,33 +34,36 @@
public class NexusServiceImpl {
@OperationImpl
public OperationHandler<NexusService.EchoInput, NexusService.EchoOutput> 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<NexusService.HelloInput, NexusService.HelloOutput> 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);
}
}
Loading