Skip to content

🧭 Azure Functions with .NET Aspire πŸŸͺ β€” Worker-Queue-Cache Architecture

Notifications You must be signed in to change notification settings

kimtth/dotnet-aspire-worker-queue-cache

Repository files navigation

Integrating Azure Functions with .NET Aspire: Web-Queue-Worker Architecture

This project demonstrates how to integrate Azure Functions with .NET Aspire, showcasing a Web-Queue-Worker architecture style. It modified the default QuickStart template.

🧭 Configurations

  1. The project uses the Queue, Redis, and Cosmos DB. These are automatically initialized by .NET Aspire

  2. Update appsettings.sample.json and local.settings.sample.json with your values.

  3. To get started:

    • Open the solution in Visual Studio.
    • Right-click the AppHost project in Solution Explorer.
    • Select 'Set as Startup Project'.
    • Press F5 (or Ctrl + F5 to run without debugging) to launch the app.
  4. Once running, the .NET Aspire dashboard will open in your browser:

    ui
  5. .NET Aspire WebFrontend

    ui

References & Resources

Sequence Diagram: Web β†’ Queue β†’ Worker

sequenceDiagram
    participant User
    participant Web as Web Frontend
    participant API as API Service
    participant Queue as Azure Queue ⟳
    participant Worker as Azure Function Worker πŸ‘·
    participant Cache as Redis Cache πŸ”„
    participant DB as Cosmos DB πŸ—„οΈ

    User->>Web: Submit request
    Web->>API: Forward request
    API->>DB: Save request history (Status: Pending)
    API->>Queue: Send message with request ID
    Note over Queue: Message contains RequestHistory JSON
    
    Queue-->>Worker: Trigger QueueProcessor function
    Worker->>Worker: Deserialize message
    Note over Worker: Process the request
    Worker->>DB: Update status to "Completed"
    DB->>Cache: Store in cache (request:{id})
    DB->>Cache: Invalidate user request list cache
    
    User->>Web: Check request status
    Web->>Cache: Try get from cache (requests)
    alt Cache hit
        Cache-->>Web: Return cached data
    else Cache miss
        Web->>DB: Query all request history
        DB-->>Web: Return request history
        Web->>Cache: Cache result (requests)
    end
    Web-->>User: Display all requests
Loading

About

🧭 Azure Functions with .NET Aspire πŸŸͺ β€” Worker-Queue-Cache Architecture

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published