|
| 1 | +# Nexus operation backed by a standalone Activity |
| 2 | + |
| 3 | +This sample shows how to implement a `TemporalOperationHandler` that starts a |
| 4 | +standalone Activity as the backing execution for a Nexus operation. When the Activity |
| 5 | +finishes, Temporal delivers its result to the Nexus caller. The default handler |
| 6 | +cancellation implementation also forwards Nexus cancellation to the Activity. |
| 7 | + |
| 8 | +The APIs used by this sample are experimental and may change incompatibly. |
| 9 | + |
| 10 | +### Sample structure |
| 11 | + |
| 12 | +- [service.py](./service.py) defines the Nexus service shared by caller and handler. |
| 13 | +- [activity.py](./activity.py) defines the standalone Activity. |
| 14 | +- [handler.py](./handler.py) implements `TemporalOperationHandler.start_operation`. |
| 15 | +- [worker.py](./worker.py) hosts the Nexus handler and Activity. |
| 16 | +- [starter.py](./starter.py) executes the Nexus operation from client code. |
| 17 | + |
| 18 | +## Run locally |
| 19 | + |
| 20 | +This sample requires the [Temporal dev server build that supports standalone Nexus operations](https://docs.temporal.io/standalone-nexus-operation#temporal-cli-support) and Activity |
| 21 | +callbacks enabled. |
| 22 | + |
| 23 | +1. Start the server with caller and handler namespaces: |
| 24 | + |
| 25 | + ```bash |
| 26 | + ./temporal server start-dev \ |
| 27 | + --dynamic-config-value activity.enableCallbacks=true \ |
| 28 | + --namespace nexus-standalone-activity-caller \ |
| 29 | + --namespace nexus-standalone-activity-handler |
| 30 | + ``` |
| 31 | + |
| 32 | +2. Create an endpoint targeting the handler namespace and task queue: |
| 33 | + |
| 34 | + ```bash |
| 35 | + ./temporal operator nexus endpoint create \ |
| 36 | + --name nexus-standalone-activity-endpoint \ |
| 37 | + --target-namespace nexus-standalone-activity-handler \ |
| 38 | + --target-task-queue nexus-standalone-activity-handler |
| 39 | + ``` |
| 40 | + |
| 41 | +3. Start the handler Worker: |
| 42 | + |
| 43 | + ```bash |
| 44 | + TEMPORAL_NAMESPACE=nexus-standalone-activity-handler \ |
| 45 | + uv run nexus_standalone_activity/worker.py |
| 46 | + ``` |
| 47 | + |
| 48 | +4. Execute the operation from the caller namespace: |
| 49 | + |
| 50 | + ```bash |
| 51 | + TEMPORAL_NAMESPACE=nexus-standalone-activity-caller \ |
| 52 | + uv run nexus_standalone_activity/starter.py |
| 53 | + ``` |
| 54 | + |
| 55 | +Expected output: |
| 56 | + |
| 57 | +```text |
| 58 | +Hello, World! |
| 59 | +``` |
0 commit comments