|
23 | 23 | import io.nexusrpc.handler.OperationImpl; |
24 | 24 | import io.nexusrpc.handler.ServiceImpl; |
25 | 25 | import io.temporal.client.WorkflowOptions; |
26 | | -import io.temporal.nexus.WorkflowClientOperationHandlers; |
| 26 | +import io.temporal.nexus.Nexus; |
| 27 | +import io.temporal.nexus.WorkflowRunOperation; |
27 | 28 | import io.temporal.samples.nexus.service.NexusService; |
28 | 29 |
|
29 | 30 | // To create a service implementation, annotate the class with @ServiceImpl and provide the |
|
33 | 34 | public class NexusServiceImpl { |
34 | 35 | @OperationImpl |
35 | 36 | 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())); |
44 | 45 | } |
45 | 46 |
|
46 | 47 | @OperationImpl |
47 | 48 | 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 |
49 | 50 | // 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()) |
63 | 67 | ::hello); |
64 | 68 | } |
65 | 69 | } |
0 commit comments