Lesson 4 Complete Solution
This folder contains the complete solution for Lesson 4: HelloWorkflow - your first Temporal workflow and activity.
What's Included
Workflow Components
workflow/HelloWorkflow.kt
- Workflow interface with@WorkflowInterface
workflow/HelloWorkflowImpl.kt
- Workflow implementation that orchestrates the activity
Activity Components
activity/GreetingActivity.kt
- Activity interface with@ActivityInterface
activity/GreetingActivityImpl.kt
- Activity implementation with actual business logic
Configuration & Infrastructure
config/TemporalConfig.kt
- Complete Temporal setup with worker registrationrunner/HelloWorkflowRunner.kt
- CommandLineRunner that executes the workflowTemporalBootcampApplication.kt
- Spring Boot main class
How It Works
- Spring Boot starts and initializes Temporal configuration
- Worker starts and registers HelloWorkflow and GreetingActivity
- HelloWorkflowRunner executes automatically via CommandLineRunner
- Workflow stub is created with proper task queue and workflow ID
- Workflow executes and calls the GreetingActivity
- Activity generates a greeting message
- Result is returned and logged to console
Running This Solution
Start Temporal server:
temporal server start-dev
Run the application
Expected Output:
โ Temporal worker started successfully for HelloWorkflow! Task Queue: lesson4-hello-queue Registered: HelloWorkflow, GreetingActivity ๐ Running HelloWorkflow... โ Workflow completed! Result: Hello, Temporal Learner! Welcome to Temporal workflows! ๐ Check the Temporal Web UI at http://localhost:8233
Verification
In the Console
You should see successful workflow execution with the greeting message.
In Temporal Web UI (http://localhost:8233)
- Workflows tab - Shows your workflow execution
- Task Queues tab - Shows
lesson4-hello-queue
with 1 worker - Workers tab - Shows your worker with registered capabilities
Workflow Details in Web UI
- Workflow ID:
hello-workflow-{timestamp}
- Status: Completed
- Execution timeline showing workflow and activity execution
Key Learning Points
Workflow vs Activity
- Workflow (HelloWorkflowImpl): Orchestration logic, deterministic, can be replayed
- Activity (GreetingActivityImpl): Business logic, can fail and retry, handles external calls
Annotations
@WorkflowInterface
/@WorkflowMethod
- Define workflow contracts@ActivityInterface
/@ActivityMethod
- Define activity contracts@Component
- Spring manages activity as a bean
Configuration
- Task Queue: Named channel connecting workflow requests to workers
- Activity Options: Timeouts and retry policies
- Worker Registration: Must register both workflows and activities
Execution Flow
- Client creates workflow stub
- Client calls workflow method
- Temporal routes to appropriate worker
- Worker executes workflow code
- Workflow calls activity via stub
- Worker executes activity code
- Results flow back through the chain
Next Steps
Now that you understand the basic workflow and activity pattern, you're ready for more advanced concepts in the remaining lessons!