Standalone client sample demonstrating how to interact with the unified order processing contract
This sample demonstrates that a single client can interact with any worker implementation of the unified contract.
This client package demonstrates that:
- Both
order-processing-workerandorder-processing-worker-nestjsworkers implement the same unified contract - A single client works with any worker implementation
- From the client's perspective, all workers are identical
- Workers handle errors internally using the Result/Future pattern with ActivityError
- Start Temporal server:
temporal server start-dev- Build the workspace from the repository root:
cd ../..
pnpm install && pnpm build- Start a worker (choose one):
Option A: Standard Worker
cd ../order-processing-worker
pnpm devOption B: NestJS Worker
cd ../order-processing-worker-nestjs
pnpm dev- Run the client:
cd ../order-processing-client
pnpm devThe client includes integration tests that verify:
- Workflow execution through the contract
- Proper input validation via contract schema
- Correct output types matching contract schema
- Workflow history and metadata access
Run tests:
pnpm test- Same Contract: The client uses
orderProcessingContractfrom@temporal-contract/sample-order-processing-contract - Same Task Queue: All workers listen on the same task queue:
"order-processing" - Worker Agnostic: The client doesn't know or care which worker implementation is running
- Type Safety: All inputs and outputs are validated against the contract schemas
The unified contract (orderProcessingContract) defines:
- Global activities:
log,sendNotification - Workflow:
processOrder- Activities:
processPayment,reserveInventory,releaseInventory,createShipment,refundPayment
- Activities:
Both workers implement the exact same contract but with different frameworks:
-
Standard Worker (
samples/order-processing-worker)- Uses
@temporal-contract/worker - Activities use Result/Future pattern with ActivityError
- Clean Architecture with dependency injection
- Standalone TypeScript application
- Uses
-
NestJS Worker (
samples/order-processing-worker-nestjs)- Uses
@temporal-contract/worker-nestjs - Activities use Result/Future pattern with ActivityError
- NestJS dependency injection and decorators
- Better for NestJS-based applications
- Uses
From the client's perspective, there's no difference between the workers:
- Same contract import
- Same workflow names
- Same activity signatures
- Same result types
This demonstrates the power of contract-driven development - implementations can vary while maintaining compatibility.
MIT