.NET Aspire is designed to enhance the development of cloud-native .NET applications by providing a consistent set of tools and patterns for building and running distributed apps. It helps developers with:
- Orchestration: Simplifies the management of multi-project applications and their dependencies in local development environments.
- Integrations: Offers NuGet packages for common services (e.g., Redis, PostgreSQL) with standardized interfaces for seamless app integration.
- Tooling: Provides project templates and tooling support for Visual Studio, Visual Studio Code, and the .NET CLI, making it easier to create and work with .NET Aspire projects.
This application implements a basic file process designed to handle COVID-related files. It supports file uploading, processing, data aggregation, and storage into multiple databases, while also providing an endpoint for retrieving the aggregated summary.
The application uses various resources like:
- Azure Blob Storage (Emulator)
- Azure Service Bus (Emulator)
- MongoDB
- PostgreSQL
- Redis
- .NET 9 SDK
- .NET Aspire
- Docker
- Automatic Upload: A background service monitors a directory for new files. When a new file is detected, it is uploaded to Azure Blob Storage, and a message is sent to the Azure Service Bus Queue.
- Typed HttpClient: Uses a typed HttpClient
FileUploaderClient
to upload files through the API. - Azure Blob Storage: Used for storing uploaded files.
- Azure Service Bus Queue: Used to send messages upon file upload for
File Details Service
processing.
- Message Processing: Reads messages from the Azure Service Bus queue for file processing.
- File Processing: Downloads files from Blob Storage and reads them using the CsvHelper package.
- Data Insertion: Inserts detailed data into MongoDB.
- Message Forwarding: Sends a message to the File Summary Service once processing is complete.
- Message Processing: Reads messages from the queue for aggregated data processing.
- Data Aggregation: Aggregates values from MongoDB.
- Data Insertion: Saves the aggregated data into PostgreSQL.
- Caching: Caches the aggregated summary data into Redis for fast access.
With .NET Aspire, we can get the full observability of your application and services, including:
- MongoExpress Dashboard: A web-based interface for managing MongoDB and viewing your stored data.
- Postgres-PgAdmin / PgWeb Dashboards: Web-based interfaces to interact with your PostgreSQL database.
- Redis Cache Insights: Visualize and manage the Redis cache with built-in dashboards, providing deep insights into cache usage and performance.
-
Clone the repository:
git clone https://github.com/dianper/microservice-aspire.git cd microservice-aspire
-
Set up Docker containers for required services:
- Docker is required to run the application dependencies.
-
Run the application:
dotnet run
Retrieve the global summary. The service checks Redis for cached data first; if not found, it queries PostgreSQL.
Manually upload a CSV file to be processed.
- Request body: Multipart form-data containing the file.
Let's use Aspir8 to generate the Docker Compose file and Helm chart for the application.
-
Install Aspir8:
dotnet tool install -g aspirate
-
Generating Docker Compose:
aspirate generate --output-format compose
-
Generating Helm Chart:
aspirate generate --output-format helm