|
| 1 | +# Durable Task JavaScript SDK - Examples |
| 2 | + |
| 3 | +This directory contains examples demonstrating various features of the Durable Task JavaScript SDK. |
| 4 | + |
| 5 | +## Example Applications |
| 6 | + |
| 7 | +Each example is a standalone application with its own README and can be run independently. |
| 8 | + |
| 9 | +### Basic Orchestration Examples |
| 10 | + |
| 11 | +Located in `hello-world/`: |
| 12 | + |
| 13 | +- **[Activity Sequence](./hello-world/activity-sequence.ts)**: Basic orchestration that calls three activities in sequence. |
| 14 | +- **[Fan-out/Fan-in](./hello-world/fanout-fanin.ts)**: Orchestration that schedules multiple activities in parallel and aggregates results. |
| 15 | +- **[Human Interaction](./hello-world/human_interaction.ts)**: Demonstrates waiting for external events in orchestrations. |
| 16 | + |
| 17 | +### Durable Entities Examples |
| 18 | + |
| 19 | +Durable Entities are stateful objects with built-in concurrency control: |
| 20 | + |
| 21 | +- **[Entity Counter](./entity-counter/)**: Simple counter entity demonstrating basic entity operations, signaling, and state management. |
| 22 | +- **[Entity Orchestration](./entity-orchestration/)**: Bank transfer scenario using entity locking for atomic cross-entity operations. |
| 23 | + |
| 24 | +### Azure Integration Examples |
| 25 | + |
| 26 | +- **[Azure Managed DTS](./azure-managed/)**: Integration with Azure Managed Durable Task Scheduler using Azure authentication. |
| 27 | +- **[Azure Managed DTS (Simple)](./azure-managed-dts.ts)**: Simplified version showing Azure DTS connection setup. |
| 28 | + |
| 29 | +## Prerequisites |
| 30 | + |
| 31 | +Examples require a Durable Task-compatible backend. Choose one: |
| 32 | + |
| 33 | +### Option 1: DTS Emulator (Recommended for Testing) |
| 34 | + |
| 35 | +The DTS Emulator is ideal for local development and testing: |
| 36 | + |
| 37 | +```bash |
| 38 | +docker run --name dts-emulator -i -p 8080:8080 -d --rm mcr.microsoft.com/dts/dts-emulator:latest |
| 39 | +``` |
| 40 | + |
| 41 | +Most standalone examples can run against the emulator using: |
| 42 | + |
| 43 | +```bash |
| 44 | +cd examples/entity-counter |
| 45 | +npm run start:emulator |
| 46 | +``` |
| 47 | + |
| 48 | +### Option 2: Local Sidecar |
| 49 | + |
| 50 | +Install and run locally (requires Go 1.18+): |
| 51 | + |
| 52 | +```bash |
| 53 | +# Install Dapr CLI (includes Durable Task sidecar) |
| 54 | +https://docs.dapr.io/getting-started/install-dapr-cli/ |
| 55 | + |
| 56 | +# Or build from source |
| 57 | +git clone https://github.com/microsoft/durabletask-go |
| 58 | +cd durabletask-go |
| 59 | +go run . start --backend Emulator |
| 60 | +``` |
| 61 | + |
| 62 | +The sidecar runs on `localhost:4001` by default. |
| 63 | + |
| 64 | +### Option 3: Unofficial Sidecar Docker Image |
| 65 | + |
| 66 | +For quick local development: |
| 67 | + |
| 68 | +```bash |
| 69 | +docker run \ |
| 70 | + --name durabletask-sidecar -d --rm \ |
| 71 | + -p 4001:4001 \ |
| 72 | + --env 'DURABLETASK_SIDECAR_LOGLEVEL=Debug' \ |
| 73 | + kaibocai/durabletask-sidecar:latest start \ |
| 74 | + --backend Emulator |
| 75 | +``` |
| 76 | + |
| 77 | +## Running Examples |
| 78 | + |
| 79 | +### Standalone Applications (Recommended) |
| 80 | + |
| 81 | +Standalone applications include `entity-counter` and `entity-orchestration`. Each has its own `package.json`: |
| 82 | + |
| 83 | +```bash |
| 84 | +cd examples/entity-counter |
| 85 | +npm run start:emulator # Run against DTS emulator |
| 86 | +# OR |
| 87 | +npm run start # Run against local sidecar on localhost:4001 |
| 88 | +``` |
| 89 | + |
| 90 | +See individual README files for detailed instructions. |
| 91 | + |
| 92 | +### Single-File Examples |
| 93 | + |
| 94 | +Basic orchestration examples in `hello-world/` can be run directly: |
| 95 | + |
| 96 | +```bash |
| 97 | +npm run example ./examples/hello-world/activity-sequence.ts |
| 98 | +``` |
| 99 | + |
| 100 | +## Testing Against DTS Emulator |
| 101 | + |
| 102 | +All entity examples are designed to work with the DTS emulator: |
| 103 | + |
| 104 | +1. Start the DTS emulator: |
| 105 | + ```bash |
| 106 | + docker run --name dts-emulator -i -p 8080:8080 -d --rm mcr.microsoft.com/dts/dts-emulator:latest |
| 107 | + ``` |
| 108 | + |
| 109 | +2. Run the example: |
| 110 | + ```bash |
| 111 | + cd examples/entity-counter |
| 112 | + npm run start:emulator |
| 113 | + ``` |
| 114 | + |
| 115 | +The emulator provides a clean, isolated environment for testing without requiring external dependencies. |
| 116 | + |
| 117 | +## Azure Managed DTS |
| 118 | + |
| 119 | +For production scenarios with Azure, see the [Azure Managed DTS example](./azure-managed/) which demonstrates: |
| 120 | +- Connection string configuration |
| 121 | +- Azure authentication with DefaultAzureCredential |
| 122 | +- Environment-based configuration |
| 123 | + |
| 124 | +## Documentation |
| 125 | + |
| 126 | +For more information about Durable Task concepts: |
| 127 | + |
| 128 | +- **Orchestrations**: Workflow definitions that coordinate activities |
| 129 | +- **Activities**: Units of work executed by orchestrations |
| 130 | +- **Entities**: Stateful actors with automatic concurrency control |
| 131 | +- **Entity Locking**: Critical sections for atomic multi-entity operations |
| 132 | + |
| 133 | +See the main [README](../README.md) for comprehensive documentation. |
0 commit comments