This repository is an example project demonstrating how to use the Asynchronous Request Reply pattern with Azure Service Bus. The solution consists of a Frontend API and a Backend Worker Microservice.
FrontendApi/
: Contains the Frontend API project.Worker/
: Contains the Backend Worker Microservice project.Bicep/
: Contains the Bicep templates for creating the Service Bus resource in Azure.
The Frontend API receives a call via its REST endpoint. The request body is a JSON document in the following format:
{ "Content": "some message here" }
Upon receiving the document, the API places the message into the request service bus topic. The caller then receives an HTTP 202 response with a redirect URL to the status endpoint. The caller can perform long polling on this status endpoint. While the long-running process is still executing, the status endpoint will return HTTP 202. Once the process is complete, it returns HTTP 201 with a redirect URL in the status body.
The Backend Worker Microservice subscribes to the request topic and processes the messages. It deserializes the message, creates a record in its in-memory datastore, and sends a response message to the response service bus topic. The Frontend API has a background process that subscribes to this response topic, updates the status accordingly, and informs the caller via the status endpoint.
- .NET 6 SDK
- Azure Subscription
- Azure Service Bus
-
Clone the repository:
git clone git@github.com:harishnarain/AsyncRequestReply.git
-
Navigate to the
Bicep/
folder and deploy the Service Bus resource:az deployment group create --resource-group <your-resource-group> --template-file servicebus.bicep
-
Build and run the Frontend API:
cd FrontendApi dotnet build dotnet run
-
Build and run the Backend Worker Microservice:
cd Worker dotnet build dotnet run
Follow the respective README files in the FrontendApi
and Worker
folders for more details.
This project showcases how to implement the Asynchronous Request Reply pattern using Azure Service Bus in a .NET Core solution. By following the steps provided, you can understand and replicate this pattern in your own projects.
Contributions are welcome! Please fork the repository and submit pull requests.
This project is licensed under the MIT License.