Giter Site home page Giter Site logo

camel-saga-quickstart's Introduction

Camel Saga Quickstart

This quickstarts demonstrates how to use the new saga feature of Camel 2.21.

It runs on Kubernetes or Openshift. You can install a development version, like Minishift or Minikube.

Saga Quickstart System

The camel-saga-app module has the following route:

from("timer:clock?period=5s")
  .saga()
    .setHeader("id", header(Exchange.TIMER_COUNTER))
    .setHeader(Exchange.HTTP_METHOD, constant("POST"))
    .log("Executing saga #${header.id}")
    .to("http4://camel-saga-train-service:8080/api/train/buy/seat")
    .to("http4://camel-saga-flight-service:8080/api/flight/buy");

It executes 2 remote actions within a saga:

  • Buy a train ticket
  • Buy an airplane ticket

Each action in turn will make a call to the payment service within the context of the saga. Calls to payment fail with 15% probability.

Since all actions are executed in the context of a saga, whenever one of the payment action fails (or another action, for any reason), the whole saga is compensated (cancelled) automatically.

Each atomic action declares its corresponding compensating action using the new Saga EIP DSL. For example, the train route is:

rest().post("/train/buy/seat")
  .param().type(RestParamType.header).name("id").required(true).endParam()
  .route()
  .saga()
    .propagation(SagaPropagation.SUPPORTS)
    .option("id", header("id"))
    .compensation("direct:cancelPurchase") // <-- compensation
  .log("Buying train seat #${header.id}")
  .to("http4://camel-saga-payment-service:8080/api/pay?bridgeEndpoint=true&type=train")
  .log("Payment for train #${header.id} done");

from("direct:cancelPurchase") // <-- compensation points to this
  .log("Train purchase #${header.id} has been cancelled");

Requirements

Openshift or Kubernetes

You can install Minishift.

Running the demo

This project uses the Fabric8 Maven Plugin to deploy itself automatically to Openshift or Kubernetes.

After you connect to the cluster, type the following command on a terminal from the repository root:

oc create -f lra-coordinator.yaml
mvn clean fabric8:deploy

Look into Openshift/Kubernetes console, all components will be deployed. You can follow the logs of the different services to see compensating actions.

camel-saga-quickstart's People

Contributors

nicolaferraro avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.