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 registration
  • runner/HelloWorkflowRunner.kt - CommandLineRunner that executes the workflow
  • TemporalBootcampApplication.kt - Spring Boot main class

How It Works

  1. Spring Boot starts and initializes Temporal configuration
  2. Worker starts and registers HelloWorkflow and GreetingActivity
  3. HelloWorkflowRunner executes automatically via CommandLineRunner
  4. Workflow stub is created with proper task queue and workflow ID
  5. Workflow executes and calls the GreetingActivity
  6. Activity generates a greeting message
  7. Result is returned and logged to console

Running This Solution

  1. Start Temporal server:

    temporal server start-dev
    
  2. Run the application

  3. 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)

  1. Workflows tab - Shows your workflow execution
  2. Task Queues tab - Shows lesson4-hello-queue with 1 worker
  3. 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

  1. Client creates workflow stub
  2. Client calls workflow method
  3. Temporal routes to appropriate worker
  4. Worker executes workflow code
  5. Workflow calls activity via stub
  6. Worker executes activity code
  7. 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!

results matching ""

    No results matching ""