|
| 1 | +# Greetings Sample |
| 2 | + |
| 3 | +This sample demonstrates **sequential activity execution** - running multiple activities one after another, passing results between them. |
| 4 | + |
| 5 | +> **Looking for a visual guide?** See [new_samples/hello_world](../../../../new_samples/hello_world/) for a step-by-step tutorial with screenshots. |
| 6 | +
|
| 7 | + |
| 8 | +## How It Works |
| 9 | + |
| 10 | +The workflow executes 3 activities in sequence: |
| 11 | + |
| 12 | +``` |
| 13 | +┌─────────────────┐ ┌─────────────────┐ ┌─────────────────────┐ |
| 14 | +│ getGreeting() │───▶│ getName() │───▶│ sayGreeting(g, n) │ |
| 15 | +│ returns "Hello" │ │ returns "Cadence"│ │ returns "Hello │ |
| 16 | +└─────────────────┘ └─────────────────┘ │ Cadence!" │ |
| 17 | + └─────────────────────┘ |
| 18 | +``` |
| 19 | + |
| 20 | +## Prerequisites |
| 21 | + |
| 22 | +1. Cadence server running (see [main README](../../../../README.md)) |
| 23 | +2. Build the samples: |
| 24 | + ```bash |
| 25 | + make |
| 26 | + ``` |
| 27 | + |
| 28 | +## Running the Sample |
| 29 | + |
| 30 | +### Step 1: Start the Worker |
| 31 | + |
| 32 | +```bash |
| 33 | +./bin/greetings -m worker |
| 34 | +``` |
| 35 | + |
| 36 | +### Step 2: Trigger the Workflow |
| 37 | + |
| 38 | +```bash |
| 39 | +./bin/greetings -m trigger |
| 40 | +``` |
| 41 | + |
| 42 | +### Step 3: View the Result |
| 43 | + |
| 44 | +Check the worker terminal: |
| 45 | +``` |
| 46 | +Workflow completed. {"Result": "Greeting: Hello Cadence!\n"} |
| 47 | +``` |
| 48 | + |
| 49 | +Or view in the Cadence Web UI at [localhost:8088](http://localhost:8088). |
| 50 | + |
| 51 | +## Key Code |
| 52 | + |
| 53 | +### Sequential Execution Pattern |
| 54 | + |
| 55 | +```go |
| 56 | +// Activity 1: Get greeting |
| 57 | +var greetResult string |
| 58 | +err := workflow.ExecuteActivity(ctx, getGreetingActivity).Get(ctx, &greetResult) |
| 59 | + |
| 60 | +// Activity 2: Get name |
| 61 | +var nameResult string |
| 62 | +err = workflow.ExecuteActivity(ctx, getNameActivity).Get(ctx, &nameResult) |
| 63 | + |
| 64 | +// Activity 3: Combine results |
| 65 | +var sayResult string |
| 66 | +err = workflow.ExecuteActivity(ctx, sayGreetingActivity, greetResult, nameResult).Get(ctx, &sayResult) |
| 67 | +``` |
| 68 | + |
| 69 | +Each `ExecuteActivity().Get()` blocks until the activity completes, ensuring sequential execution. |
| 70 | + |
| 71 | +## Testing |
| 72 | + |
| 73 | +```bash |
| 74 | +# Unit tests |
| 75 | +go test -v ./cmd/samples/recipes/greetings/ -run TestUnitTestSuite |
| 76 | + |
| 77 | +# Replay tests |
| 78 | +go test -v ./cmd/samples/recipes/greetings/ -run TestReplayWorkflowHistoryFromFile |
| 79 | +``` |
| 80 | + |
| 81 | +## References |
| 82 | + |
| 83 | +- [Cadence Documentation](https://cadenceworkflow.io) |
| 84 | +- [Activity Basics](https://cadenceworkflow.io/docs/concepts/activities/) |
| 85 | + |
0 commit comments