Lesson 5 Complete Solution
This lesson demonstrates how to create a simple workflow that calls an activity to perform calculations.
What's Included
workflow/CalculatorWorkflow.kt
- Simple workflow interfaceworkflow/CalculatorWorkflowImpl.kt
- Workflow implementation that calls an activityactivity/MathActivity.kt
- Activity interface for math operationsactivity/MathActivityImpl.kt
- Activity implementation with logging
Key Learning Points
Workflow-Activity Separation
- Workflow: Orchestrates the process, handles the flow
- Activity: Does the actual work (calculations, I/O, etc.)
Activity Stubs
- Workflows call activities through stubs, not directly
- Stubs are configured with timeouts and retry policies
- The call looks like a regular method call but goes through Temporal
Logging Strategy
- Use
Workflow.getLogger()
in workflows - Use regular logging in activities
- This helps track execution flow in the Temporal Web UI
How It Works
- Workflow receives two numbers as input
- Workflow calls the math activity via stub
- Activity performs the calculation with logging
- Activity returns the result
- Workflow returns the final result
Running This Code
This lesson focuses on the core workflow and activity code. To run it:
- Register these components with a Temporal worker
- Create a workflow stub and call the
add
method - Check logs and Temporal Web UI for execution details
Next Steps
Lesson 6 will show how to organize workflows and activities into cleaner, separate files following best practices.