This sample demonstrates:
- How to define a Nexus Service;
- How to call a Nexus Operation from a Workflow;
- How to implement a Nexus Operation handler using the Synchronous handler form;
- How to implement a Nexus Operation handler that starts a Temporal Workflow;
- How to use Nexus to make calls across Temporal namespaces.
src/api.ts- Defines the Nexus Service, including its input and output types.src/caller/- Sample Workflows that call the Nexus Operations.src/service/- The Nexus Service handler, together with a Workflow used by one of the Nexus Operations.src/starter.ts- Starter code, to run the Workflow.
Instructions below assume the following:
- Install the latest Temporal CLI (
v1.4.1or higher recommended) - Install the latest Temporal TypeScript SDK (
v1.13.0or higher)
:::tip SUPPORT, STABILITY, and DEPENDENCY INFO
Temporal TypeScript SDK support for Nexus is at Pre-release.
All APIs are experimental and may be subject to backwards-incompatible changes.
:::
-
Install NPM dependencies:
npm install # or `pnpm` or `yarn` -
Make sure you have a local Temporal Server running:
temporal server start-dev --port 7233
-
Create the expected namespaces:
temporal operator namespace create --namespace my-caller-namespace
temporal operator namespace create --namespace my-target-namespace- Setup the Nexus Endpoint on the caller namespace:
temporal operator nexus endpoint create \
--name my-nexus-endpoint-name \
--target-namespace my-target-namespace \
--target-task-queue my-handler-task-queue-
Run
npm run start.serviceto start the Worker that will be serving the Nexus Operation handlers and its associated Workflows. That Worker connects to themy-target-namespacenamespace. -
In another shell, run
npm run start.callerto start the Worker that will be serving the Caller Workflows. That Worker connects to themy-caller-namespacenamespace. -
In a third shell,
npm run workflowto start an instance of the caller Workflows.
Example output:
Echo message: This message is from the client
Hello message: Hello, Temporal!