This project demonstrates the implementation of the Source-Transform-Sink pattern in an ASP.NET Core application using Hangfire for background job scheduling.
The Source-Transform-Sink pattern is a common design pattern in data processing systems, where:
- Source: Fetches data from an external or internal source (e.g., API, database).
- Transform: Processes, transforms, or modifies the data according to business logic.
- Sink: Sends the transformed data to its final destination (e.g., console, database, file).
- Process: a process that uses sources, transformations, and sink to load data from a Data Source and save on data repository (Sink).
In this project, we implement a system that reads user data from an API (Source), processes it (Transform), and prints the data to the console (Sink).
The process follows these three steps:
-
Source: Fetches data from an API.
- The
UserSource
class is responsible for retrieving user data from an API. This can be a real API or simulated JSON data, depending on the environment.
- The
-
Transform: Modifies the fetched data.
- The
UserTransformer
class takes the raw JSON data and transforms it into a structured format (e.g., a list ofUserDto
objects).
- The
-
Sink: Outputs the transformed data to the final destination.
- The
ConsoleSink
class takes the transformed data and prints it to the console as the final step.
- The
This entire process is orchestrated using Hangfire, which allows the process to run as a background job at regular intervals (e.g., every minute).
- UserSource: Responsible for fetching data from an external source (API).
- UserTransformer: Transforms raw data (JSON) into structured objects.
- ConsoleSink: Prints the transformed data to the console.
- ProcessFromAPIToConsole: Orchestrates the whole process by combining Source, Transform, and Sink.
To run this application locally:
- Clone the repository and navigate to the project directory.
- Install Hangfire dependencies by running
dotnet restore
. - Start the application by running
dotnet run
. - The Hangfire Dashboard will be available at http://localhost:5000/.
- Hangfire will execute the Source-Transform-Sink process every minute.
This project demonstrates how to implement the Source-Transform-Sink pattern in an ASP.NET Core application. It also shows how to use Hangfire for background job scheduling to automate the process of fetching, transforming, and processing data.