• Stars
    star
    164
  • Rank 223,119 (Top 5 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created almost 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Example implementation of the Saga pattern for the classic trip booking example using the lightweight open source workflow engine (Camunda) and C#.

Saga example: trip booking

The Saga pattern describes how to solve distributed (business) transactions without two-phase-commit as this does not scale in distributed systems. The basic idea is to break the overall transaction into multiple steps or activities. Only the steps internally can be performed in atomic transactions but the overall consistency is taken care of by the Saga. The Saga has the responsibility to either get the overall business transaction completed or to leave the system in a known termination state. So in case of errors a business rollback procedure is applied which occurs by calling compensation steps or activities in reverse order. A more detailed look on Sagas is available in Saga: How to implement complex business transactions without two phaseย commit

In the example hotel, car and flight booking might be done by different remote services. So there is not technical transaction, but a business transaction. When the flight booking cannot be carried out succesfully you need to cancel hotel and car.

Saga example

Using Camunda you can implement the Saga by a BPMN XML file created using the Camunda Modeler (or by a Java DSL, but this is not available in C# at the moment).

Compensation in BPMN

Run Camunda, e.g. via Docker. More details on how to run Camunda for non-Java folks can be found in Use Camunda without touching Java and get an easy-to-use REST-based orchestration and workflow engine:

docker run -d --name camunda -p 8080:8080 camunda/camunda-bpm-platform:latest

Now you can connect to the engine via REST API. You can leverage for example this unsupported client library to ease the job to access REST, which results in pretty simple code:

var camunda = new CamundaEngineClient("http://localhost:8080/engine-rest/engine/default/", null, null);
            
// Deploy the BPMN XML file from the resources
camunda.RepositoryService.Deploy("trip-booking", new List<object> {
       FileParameter.FromManifestResource(Assembly.GetExecutingAssembly(), "FlowingTripBookingSaga.Models.FlowingTripBookingSaga.bpmn") 
   });

// Register workers
registerWorker("reserve-car", externalTask => {
  // here you can do the real thing! Like a sysout :-)
  Console.WriteLine("Reserving car now...");
  camunda.ExternalTaskService.Complete(workerId, externalTask.Id);
});
registerWorker("cancel-car", externalTask => {
  Console.WriteLine("Cancelling car now...");
  camunda.ExternalTaskService.Complete(workerId, externalTask.Id);
});
registerWorker("book-hotel", externalTask => {
  Console.WriteLine("Reserving hotel now...");
  camunda.ExternalTaskService.Complete(workerId, externalTask.Id);
});
// Register more workers...

StartPolling();

string processInstanceId = camunda.BpmnWorkflowService.StartProcessInstance("FlowingTripBookingSaga", new Dictionary<string, object>()
  {
    {"someBookingData", "..." }
  });

}

The real logic is in the callbacks.

The engine will take care of state handling, compensation and could also handle timeouts and escalations.

Cockpit Screenshot

Get started

You need

  • Visual Studio

Required steps

docker run -d --name camunda -p 8080:8080 camunda/camunda-bpm-platform:latest
  • Run the Program.cs class as this is a main application doing everything and starting exactly one Saga that is always "crashing" in the flight booking.
  • If you like you can access the Camunda webapplication on http://localhost:8080/

More Repositories

1

flowing-retail

Sample application demonstrating an order fulfillment system decomposed into multiple independant components (e.g. microservices). Showing concrete implementation alternatives using e.g. Java, Spring Boot, Apache Kafka, Camunda, Zeebe, ...
Java
1,221
star
2

trip-booking-saga-java

Example implementation of the Saga pattern for the classic trip booking example using the lightweight open source workflow engine (Camunda).
Java
268
star
3

camunda-7-springboot-amqp-microservice-cloud-example

Simple example using Camunda and Spring Boot to define a simple microservice communcating via AMQP, fully unit tested and deployable in the cloud
Java
215
star
4

camunda-csharp-showcase

Showcase using Camunda BPM on .NET Platform with C# (no Java Coding required!)
C#
165
star
5

flowing-retail-old

REPLACED BY MORE CURRENT VRSION OF THIS EXAMPLE: https://github.com/berndruecker/flowing-retail
Java
63
star
6

ticket-booking-camunda-8

A ticket booking example using Camunda Cloud, RabbitMQ, REST and two sample apps (Java Spring Boot and NodeJS)
Java
26
star
7

trip-booking-saga-serverless

Standard example of the Saga pattern (trip booking) in a serverless world
JavaScript
22
star
8

customer-onboarding-camunda-8-springboot

A simple onboarding process example using BPMN, Camunda Cloud, Java, Spring Boot and REST
Java
21
star
9

flowing-retail-concept-java

Simple application showing the concepts using plain Java without infrastructure
Java
20
star
10

camunda-csharp-client

Small (hacky!) client library wrapping around the Camunda REST API. Use to get started or demo - but note that this code is not supported or build for production!
C#
19
star
11

kafka-camunda-spring-simple

Simple Java Spring Boot example connecting to Confluent Cloud (Kafka) and Camunda Cloud (Zeebe)
Java
14
star
12

zeebe-camunda-dmn

Sample how to use Camunda DMN decisions in a Zeebe Workflow
Java
11
star
13

oreilly-training-process-automation

Labs for the OReilly Training "Process Automation in Modern Architectures"
11
star
14

customer-onboarding-camunda-8-springboot-extended

Example onboarding process using Camunda Cloud, Java, Spring Boot, REST and AMQP
Java
10
star
15

processautomationbook.com

Website for the book "Practical Process Automation" with O'Reilly
CSS
7
star
16

camunda-7-on-pcf

Tutorial how to run Camunda on Pivotal Cloud Foundary (PCF)
Java
6
star
17

flowing-retail-camunda-intro

Order flow implemented as one simple Camunda process application. Small sister of the flowing-retail example showing the same use case as system of collaborating microservices.
Java
6
star
18

camunda-7-remote-spring-boot-example

Example showing how to connect to a remote Camunda Run from Spring boot for external taks and OpenAPI REST calls
Java
6
star
19

kafka-connect-zeebe-benchmark

Python
5
star
20

bpmn-resilience-patterns

Showing how to leverage BPMN and/or the Camunda BPM engine to improve resilience by certain patterns around retrying and timeouts
Java
5
star
21

zeebe-loadtest-kubernetes

Load tests for Zeebe which can be run on Kubernetes using Helm charts to provision everything automatically
Java
5
star
22

camunda-zipkin-springboot-demo

POC using Spring Boot to show that you also trace whole workflows from Camunda with Zipkin.
Java
5
star
23

flowing-retail-payment-rest-spring-statemachine

Flowing Retail payment service implemented using Spring StateMachine (as comparison for Camunda)
Java
5
star
24

camunda-engine-7-harvester

Simple POC to show how to gather information about multiple Camunda engines across the enterprise
Java
4
star
25

customer-onboarding-camunda-7

Quick and dirty demo for an onboarding process from the book "Practical Process Automation" using Camunda Platform and Spring Boot
Java
4
star
26

camunda-7-openapi-demo

Java
3
star
27

zeebe-aws-event-bridge

summer hackdays 2020 project to prototype an integration between zeebe cloud and AWS EventBridge
Java
3
star
28

mule-camunda-24

Showcase using Mule and camunda BPM for a simple order process
Java
3
star
29

camunda-ready-to-receive-patterns

Some samples how to handle if a workflow instance in Camunda is not yet ready-to-receive a message
Java
2
star
30

advanced-workflow-patterns

JavaScript
1
star
31

zeebe-benchmark-demo

Simple local benchmark for smoketest of Zeebe performance
Java
1
star
32

camunda-compensation-examples

Java
1
star
33

custom-process-landscape

1
star
34

camunda-8-junit-tests-playgorund

Project to play with latest Camunda Cloud Zeebe testing libraries
Java
1
star
35

zeebe-first-contact

Hello World example used for first contact live demos
Java
1
star
36

camunda-interactive-lab

Interactive lab to do a plublic exercise to get Camunda running on participant machines, communicating with a central cloud Camunda instance to showcase some things - and to play around :-)
Java
1
star