This sample demonstrates how to execute Nexus Operations directly from client code, without wrapping them in a caller Workflow. It shows both synchronous and workflow-backed Operations, plus listing and counting standalone Nexus Operation executions.
Temporal Typescript SDK support for Standalone Nexus Operations is at Pre-release.
All APIs are experimental and may be subject to backwards-incompatible changes.
Standalone Nexus operations require a server version that supports this feature. Use the dev server build at https://github.com/temporalio/cli/releases/tag/v1.7.2-standalone-nexus-operations.
src/api.ts- Defines the Nexus Service, including its input and output types.src/service/handler.ts- Implements the synchronousechoOperation and the workflow-backedhelloOperation.src/service/workflows.ts- Defines the Workflow used by thehelloOperation.src/service/worker.ts- Runs the Worker that hosts the Nexus Service handler.src/starter.ts- Executes standalone Nexus Operations from a Temporal Client.
A Temporal dev server with the dynamic config flags required for standalone Nexus operations:
temporal server start-dev \
--dynamic-config-value "nexusoperation.enableStandalone=true" \
--dynamic-config-value "history.enableChasmCallbacks=true"-
Install NPM dependencies:
npm install # or `pnpm` or `yarn` -
Create the Nexus endpoint:
temporal operator nexus endpoint create \ --name nexus-standalone-operations-endpoint \ --target-namespace default \ --target-task-queue nexus-standalone-operations
-
In one shell, start the Worker:
npm run worker
-
In another shell, execute the sample:
npm run starter
Example output:
Echo result: hello
Echo result from existing operation handle: hello
Started myNexusService.hello. Operation ID: hello-...
myNexusService.hello result: Hello, World!
Listing Nexus operations:
Operation ID: hello-..., Operation: hello, Status: COMPLETED
Operation ID: echo-..., Operation: echo, Status: COMPLETED
Total Nexus operations: 2
If you run the starter multiple times, the listing and count will include additional Operations for the endpoint.