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 interface
  • workflow/CalculatorWorkflowImpl.kt - Workflow implementation that calls an activity
  • activity/MathActivity.kt - Activity interface for math operations
  • activity/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

  1. Workflow receives two numbers as input
  2. Workflow calls the math activity via stub
  3. Activity performs the calculation with logging
  4. Activity returns the result
  5. Workflow returns the final result

Running This Code

This lesson focuses on the core workflow and activity code. To run it:

  1. Register these components with a Temporal worker
  2. Create a workflow stub and call the add method
  3. 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.

results matching ""

    No results matching ""