|
| 1 | +<!-- THIS IS A GENERATED FILE --> |
| 2 | +<!-- PLEASE DO NOT EDIT --> |
| 3 | + |
| 4 | +# Dynamic Invocation Sample |
| 5 | + |
| 6 | +## Prerequisites |
| 7 | + |
| 8 | +0. Install Cadence CLI. See instruction [here](https://cadenceworkflow.io/docs/cli/). |
| 9 | +1. Run the Cadence server: |
| 10 | + 1. Clone the [Cadence](https://github.com/cadence-workflow/cadence) repository if you haven't done already: `git clone https://github.com/cadence-workflow/cadence.git` |
| 11 | + 2. Run `docker compose -f docker/docker-compose.yml up` to start Cadence server |
| 12 | + 3. See more details at https://github.com/uber/cadence/blob/master/README.md |
| 13 | +2. Once everything is up and running in Docker, open [localhost:8088](localhost:8088) to view Cadence UI. |
| 14 | +3. Register the `cadence-samples` domain: |
| 15 | + |
| 16 | +```bash |
| 17 | +cadence --env development --domain cadence-samples domain register |
| 18 | +``` |
| 19 | + |
| 20 | +Refresh the [domains page](http://localhost:8088/domains) from step 2 to verify `cadence-samples` is registered. |
| 21 | + |
| 22 | +## Steps to run sample |
| 23 | + |
| 24 | +Inside the folder this sample is defined, run the following command: |
| 25 | + |
| 26 | +```bash |
| 27 | +go run . |
| 28 | +``` |
| 29 | + |
| 30 | +This will call the main function in main.go which starts the worker, which will be execute the sample workflow code |
| 31 | + |
| 32 | +## How It Works |
| 33 | + |
| 34 | +This sample demonstrates invoking activities by **string name** rather than function reference: |
| 35 | + |
| 36 | +```go |
| 37 | +// Instead of: |
| 38 | +workflow.ExecuteActivity(ctx, GetGreetingActivity) |
| 39 | + |
| 40 | +// Use string name: |
| 41 | +workflow.ExecuteActivity(ctx, "main.getGreetingActivity") |
| 42 | +``` |
| 43 | + |
| 44 | +This enables: |
| 45 | +- Plugin architectures where activities are loaded at runtime |
| 46 | +- Configuration-driven workflows |
| 47 | +- Cross-language activity invocation |
| 48 | + |
| 49 | +``` |
| 50 | +┌─────────────────────────┐ |
| 51 | +│ DynamicGreetingsWorkflow│ |
| 52 | +│ │ |
| 53 | +│ ExecuteActivity(ctx, │ |
| 54 | +│ "main.getGreeting") │──▶ GetGreetingActivity |
| 55 | +│ │ │ |
| 56 | +│ ExecuteActivity(ctx, │ |
| 57 | +│ "main.getName") │──▶ GetNameActivity |
| 58 | +│ │ │ |
| 59 | +│ ExecuteActivity(ctx, │ |
| 60 | +│ "main.sayGreeting") │──▶ SayGreetingActivity |
| 61 | +└─────────────────────────┘ |
| 62 | +``` |
| 63 | + |
| 64 | +## Running the Sample |
| 65 | + |
| 66 | +Start the worker: |
| 67 | +```bash |
| 68 | +go run . |
| 69 | +``` |
| 70 | + |
| 71 | +Trigger the workflow: |
| 72 | +```bash |
| 73 | +cadence --env development \ |
| 74 | + --domain cadence-samples \ |
| 75 | + workflow start \ |
| 76 | + --workflow_type cadence_samples.DynamicGreetingsWorkflow \ |
| 77 | + --tl cadence-samples-worker \ |
| 78 | + --et 60 |
| 79 | +``` |
| 80 | + |
| 81 | + |
| 82 | +## References |
| 83 | + |
| 84 | +* The website: https://cadenceworkflow.io |
| 85 | +* Cadence's server: https://github.com/uber/cadence |
| 86 | +* Cadence's Go client: https://github.com/uber-go/cadence-client |
| 87 | + |
0 commit comments