项目作者: gautamdhameja

项目描述 :
Saga pattern implementation using Azure Durable Functions.
高级语言: C#
项目地址: git://github.com/gautamdhameja/saga-durable-functions.git
创建时间: 2019-05-19T20:01:29Z
项目社区:https://github.com/gautamdhameja/saga-durable-functions

开源协议:MIT License

下载


Saga-Durable-Functions

Saga pattern implementation using Azure Durable Functions.

Scenario

In this example, Saga pattern is implemented as a workflow which includes booking of a flight, hotel and taxi (yeah, the most common workflow example).

To manage the state locally, ConcurrentDictionary is used to easily work across tasks. Each item in the ConcurrentDictionary is a booking which encapsulates the state of flight, hotel and taxi booking as bool values. See Models/Booking.cs and Activities/StorageService.cs for details.

For bookings and cancellations, SubOrchestrators are used which include calling activities to book and then save the booking status. As an example, see Activities/Hotel.cs for details.

Finally, a top-most main Orchestrator is used as Saga manager to call SubOrchestrators and activities.

The aim is to always have the system in a consistent state; either all three of flight, hotel and taxi are booked or none of them.

Usage

  • Clone this repo.
  • Build and run solution.
  • Using postman or any other API tool, call the following endpoint to start the workflow:
  1. GET http://localhost:7071/api/SagaClient
  • Monitor the logs in the console to check the status of bookings.

At the end of the workflow execution, the status of bookings will always be either all false or all true. Hence putting the system in an eventually consistent state.