You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/06/26 00:20:44 UTC

[GitHub] WillemJiang closed pull request #210: [SCB-244] enable servicecomb and add demo

WillemJiang closed pull request #210: [SCB-244] enable servicecomb and add demo
URL: https://github.com/apache/incubator-servicecomb-saga/pull/210
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandler.java b/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandler.java
index 82e49ef0..78a10457 100644
--- a/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandler.java
+++ b/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandler.java
@@ -22,30 +22,37 @@
 
 import java.lang.invoke.MethodHandles;
 
-import org.apache.servicecomb.saga.omega.context.OmegaContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-
 import org.apache.servicecomb.core.Handler;
 import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.apache.servicecomb.saga.omega.context.OmegaContext;
 import org.apache.servicecomb.swagger.invocation.AsyncResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class SagaConsumerHandler implements Handler {
 
   private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
   private final OmegaContext omegaContext;
 
-  public SagaConsumerHandler(@Autowired(required=false) OmegaContext omegaContext) {
-    this.omegaContext = omegaContext;
-    if (omegaContext == null) {
-      LOG.info("The OmegaContext is not injected, The SagaConsumerHandler is disabled.");
+  public SagaConsumerHandler() {
+    OmegaContext context = null;
+    try {
+      context = BeanUtils.getBean("omegaContext");
+    } catch (NullPointerException npe) {
+      LOG.warn("SagaConsumerHandler is not disabled, it's just cannot inject transaction ID.");
     }
+    this.omegaContext = context;
+  }
+
+  public SagaConsumerHandler(OmegaContext omegaContext) {
+    this.omegaContext = omegaContext;
   }
 
   @Override
   public void handle(Invocation invocation, AsyncResponse asyncResponse) throws Exception {
-    if (omegaContext!= null && omegaContext.globalTxId() != null) {
+    if (omegaContext != null && omegaContext.globalTxId() != null) {
       invocation.getContext().put(GLOBAL_TX_ID_KEY, omegaContext.globalTxId());
       invocation.getContext().put(LOCAL_TX_ID_KEY, omegaContext.localTxId());
 
@@ -54,6 +61,8 @@ public void handle(Invocation invocation, AsyncResponse asyncResponse) throws Ex
           omegaContext.globalTxId(),
           LOCAL_TX_ID_KEY,
           omegaContext.localTxId());
+    } else {
+      LOG.info("SagaConsumerHandler is not disabled, it's just cannot inject transaction ID.");
     }
 
     invocation.next(asyncResponse);
diff --git a/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandler.java b/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandler.java
index a3a72b64..2dfcab5a 100644
--- a/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandler.java
+++ b/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandler.java
@@ -22,25 +22,32 @@
 
 import java.lang.invoke.MethodHandles;
 
-import org.apache.servicecomb.saga.omega.context.OmegaContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-
 import org.apache.servicecomb.core.Handler;
 import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.apache.servicecomb.saga.omega.context.OmegaContext;
 import org.apache.servicecomb.swagger.invocation.AsyncResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class SagaProviderHandler implements Handler {
 
   private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
   private final OmegaContext omegaContext;
 
-  public SagaProviderHandler(@Autowired(required=false) OmegaContext omegaContext) {
-    this.omegaContext = omegaContext;
-    if (omegaContext == null) {
-      LOG.info("The OmegaContext is not injected, The SagaProviderHander is disabled.");
+  public SagaProviderHandler() {
+    OmegaContext context = null;
+    try {
+      context = BeanUtils.getBean("omegaContext");
+    } catch (NullPointerException npe) {
+      LOG.warn("SagaProviderHandler is not disabled, it's just cannot inject transaction ID.");
     }
+    this.omegaContext = context;
+  }
+
+  public SagaProviderHandler(OmegaContext omegaContext) {
+    this.omegaContext = omegaContext;
   }
 
   @Override
@@ -54,6 +61,8 @@ public void handle(Invocation invocation, AsyncResponse asyncResponse) throws Ex
         omegaContext.setGlobalTxId(globalTxId);
         omegaContext.setLocalTxId(invocation.getContext().get(LOCAL_TX_ID_KEY));
       }
+    } else {
+      LOG.info("SagaProviderHandler is not disabled, it's just cannot inject transaction ID.");
     }
 
     invocation.next(asyncResponse);
diff --git a/omega/omega-transport/omega-transport-servicecomb/src/test/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandlerTest.java b/omega/omega-transport/omega-transport-servicecomb/src/test/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandlerTest.java
index edf2c791..d66e3ee0 100644
--- a/omega/omega-transport/omega-transport-servicecomb/src/test/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandlerTest.java
+++ b/omega/omega-transport/omega-transport-servicecomb/src/test/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandlerTest.java
@@ -26,23 +26,26 @@
 import java.util.Map;
 import java.util.UUID;
 
+import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.saga.omega.context.IdGenerator;
 import org.apache.servicecomb.saga.omega.context.OmegaContext;
+import org.apache.servicecomb.swagger.invocation.AsyncResponse;
 import org.junit.Before;
 import org.junit.Test;
 
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.swagger.invocation.AsyncResponse;
-
 public class SagaConsumerHandlerTest {
 
   private static final String globalTxId = UUID.randomUUID().toString();
+
   private static final String localTxId = UUID.randomUUID().toString();
+
   @SuppressWarnings("unchecked")
   private final IdGenerator<String> idGenerator = mock(IdGenerator.class);
 
   private final OmegaContext omegaContext = new OmegaContext(() -> "ignored");
+
   private final Invocation invocation = mock(Invocation.class);
+
   private final AsyncResponse asyncResponse = mock(AsyncResponse.class);
 
   private final SagaConsumerHandler handler = new SagaConsumerHandler(omegaContext);
diff --git a/omega/omega-transport/omega-transport-servicecomb/src/test/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandlerTest.java b/omega/omega-transport/omega-transport-servicecomb/src/test/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandlerTest.java
index d789c935..24c277b6 100644
--- a/omega/omega-transport/omega-transport-servicecomb/src/test/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandlerTest.java
+++ b/omega/omega-transport/omega-transport-servicecomb/src/test/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandlerTest.java
@@ -30,19 +30,22 @@
 import java.util.Map;
 import java.util.UUID;
 
+import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.saga.omega.context.OmegaContext;
+import org.apache.servicecomb.swagger.invocation.AsyncResponse;
 import org.junit.Before;
 import org.junit.Test;
 
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.swagger.invocation.AsyncResponse;
-
 public class SagaProviderHandlerTest {
 
   private static final String globalTxId = UUID.randomUUID().toString();
+
   private static final String localTxId = UUID.randomUUID().toString();
+
   private final OmegaContext omegaContext = new OmegaContext(() -> "ignored");
+
   private final Invocation invocation = mock(Invocation.class);
+
   private final AsyncResponse asyncResponse = mock(AsyncResponse.class);
 
   private final SagaProviderHandler handler = new SagaProviderHandler(omegaContext);
@@ -74,5 +77,4 @@ public void doNothingInNonTransactionRequest() throws Exception {
     assertThat(omegaContext.globalTxId(), is(nullValue()));
     assertThat(omegaContext.localTxId(), is(nullValue()));
   }
-
 }
diff --git a/pom.xml b/pom.xml
index d20f11fc..4e11d2d4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,6 +65,7 @@
     <javax.activation.version>1.1.1</javax.activation.version>
     <maven-dependency-plugin.version>3.0.2</maven-dependency-plugin.version>
     <netty.version>2.0.7.Final</netty.version>
+    <java-chassis.version>1.0.0-m2</java-chassis.version>
   </properties>
 
   <name>ServiceComb Saga</name>
@@ -147,6 +148,11 @@
         <artifactId>omega-transport-dubbo</artifactId>
         <version>0.3.0-SNAPSHOT</version>
       </dependency>
+      <dependency>
+        <groupId>org.apache.servicecomb.saga</groupId>
+        <artifactId>omega-transport-servicecomb</artifactId>
+        <version>0.3.0-SNAPSHOT</version>
+      </dependency>
       <dependency>
         <groupId>org.apache.servicecomb.saga</groupId>
         <artifactId>omega-connector-grpc</artifactId>
diff --git a/saga-demo/pom.xml b/saga-demo/pom.xml
index 8b23e357..e321a167 100644
--- a/saga-demo/pom.xml
+++ b/saga-demo/pom.xml
@@ -32,6 +32,7 @@
   <modules>
     <module>saga-dubbo-demo</module>
     <module>saga-spring-cloud-demo</module>
+    <module>saga-servicecomb-demo</module>
   </modules>
 
   <dependencyManagement>
diff --git a/saga-demo/saga-servicecomb-demo/README.md b/saga-demo/saga-servicecomb-demo/README.md
new file mode 100644
index 00000000..f9cd821a
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/README.md
@@ -0,0 +1,61 @@
+# Booking Demo
+This demo simulates a booking application including three services:
+* booking
+* car
+* hotel
+
+## Prerequisites
+You will need:
+1. [JDK 1.8][jdk]
+2. [Maven 3.x][maven]
+3. [Docker][docker]
+4. [Docker compose][docker_compose]
+5. [alpha server][alpha_server]
+
+
+[jdk]: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
+[maven]: https://maven.apache.org/install.html
+[docker]: https://www.docker.com/get-docker
+[docker_compose]: https://docs.docker.com/compose/install/
+[alpha_server]: https://github.com/apache/incubator-servicecomb-saga/tree/master/alpha
+
+## Running Demo
+You can run the demo using either docker compose or executable files.
+### via docker compose
+1. run the following command to create docker images in saga project root folder.
+   ```
+   mvn clean package -DskipTests -Pdocker -Pdemo
+   ```
+2. start the whole application up(including alpha server and three demo services)
+   ```
+   docker-compose up
+   ```
+
+## User Requests by command line tools
+1. Booking 2 rooms and 2 cars, this booking will be OK.
+```
+curl -X POST http://${host_address}:8083/booking/test/2/2
+```
+Check the hotel booking status with
+```
+curl http://${host_address}:8081/bookings
+```
+Check the car booking status with
+```
+curl http://${host_address}:8082/bookings
+
+```
+
+2. Booking 3 rooms and 2 cars, this booking will cause the hotel order failed and trigger the compensate operation with car booking.
+```
+curl -X POST http://${host_address}:8083/booking/test/3/2
+```
+Check the hotel booking status with
+```
+curl http://${host_address}:8081/bookings
+```
+Check the car booking status with
+```
+curl http://${host_address}:8082/bookings
+```
+The second car booking will be marked with **cancel:true**
\ No newline at end of file
diff --git a/saga-demo/saga-servicecomb-demo/docker-compose.yaml b/saga-demo/saga-servicecomb-demo/docker-compose.yaml
new file mode 100644
index 00000000..b6e6b382
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/docker-compose.yaml
@@ -0,0 +1,93 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+version: '2.1'
+
+services:
+  database:
+    image: "postgres"
+    hostname: postgres
+    environment:
+      - POSTGRES_DB=saga
+      - POSTGRES_USER=saga
+      - POSTGRES_PASSWORD=password
+    healthcheck:
+        test: ["CMD-SHELL", "nc -z localhost 5432 &> /dev/null; echo $$?"]
+        interval: 30s
+        timeout: 10s
+        retries: 5
+
+  alpha:
+    image: "alpha-server:0.3.0-SNAPSHOT"
+    hostname: alpha-server
+    links:
+      - "database:postgresql.servicecomb.io"
+    environment:
+      - JAVA_OPTS=-Dspring.profiles.active=prd
+    healthcheck:
+        test: ["CMD-SHELL", "nc -z localhost 8080 &> /dev/null; echo $$?"]
+        interval: 30s
+        timeout: 10s
+        retries: 5
+    depends_on:
+      database:
+        condition: service_healthy
+
+  servicecenter:
+    image: "servicecomb/service-center:latest"
+    hostname: service-center
+    ports:
+      - "30100:30100"
+
+  hotel:
+    image: "scb-hotel:0.3.0-SNAPSHOT"
+    hostname: hotel
+    links:
+      - "alpha:alpha-server.servicecomb.io"
+      - "servicecenter:service-center.servicecomb.io"
+    ports:
+      - "8081:8081"
+    depends_on:
+      alpha:
+        condition: service_healthy
+
+  car:
+    image: "scb-car:0.3.0-SNAPSHOT"
+    hostname: car
+    links:
+      - "alpha:alpha-server.servicecomb.io"
+      - "servicecenter:service-center.servicecomb.io"
+    ports:
+      - "8082:8082"
+    depends_on:
+      alpha:
+        condition: service_healthy
+
+  booking:
+    image: "scb-booking:0.3.0-SNAPSHOT"
+    hostname: booking
+    links:
+      - "alpha:alpha-server.servicecomb.io"
+      - "hotel:hotel.servicecomb.io"
+      - "car:car.servicecomb.io"
+      - "servicecenter:service-center.servicecomb.io"
+    ports:
+      - "8083:8083"
+    depends_on:
+      - hotel
+      - car
+      - servicecenter
diff --git a/saga-demo/saga-servicecomb-demo/pom.xml b/saga-demo/saga-servicecomb-demo/pom.xml
new file mode 100644
index 00000000..6dec1857
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/pom.xml
@@ -0,0 +1,144 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>saga-demo</artifactId>
+    <groupId>org.apache.servicecomb.saga.demo</groupId>
+    <version>0.3.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>saga-servicecomb-demo</artifactId>
+  <name>Saga::Demo::ServiceComb-Demo</name>
+  <packaging>pom</packaging>
+
+
+  <modules>
+    <module>scb-car</module>
+    <module>scb-hotel</module>
+    <module>scb-booking</module>
+  </modules>
+
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.apache.servicecomb</groupId>
+        <artifactId>java-chassis-dependencies</artifactId>
+        <version>${java-chassis.version}</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
+  <dependencies>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+      <version>20.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>3.6</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>spring-boot-starter-provider</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate-validator</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb.saga</groupId>
+      <artifactId>omega-spring-starter</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb.saga</groupId>
+      <artifactId>omega-transport-servicecomb</artifactId>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <!-- mixin plugin configurations declared in another pom,
+      just like importing dependencies managed in another pom -->
+      <plugin>
+        <groupId>com.github.odavid.maven.plugins</groupId>
+        <artifactId>mixin-maven-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>repackage</goal>
+            </goals>
+            <configuration>
+              <classifier>exec</classifier>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <profiles>
+    <profile>
+      <id>docker</id>
+      <activation>
+        <file>
+          <exists>/var/run/docker.sock</exists>
+        </file>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>io.fabric8</groupId>
+            <artifactId>docker-maven-plugin</artifactId>
+          </plugin>
+          <plugin>
+            <groupId>org.commonjava.maven.plugins</groupId>
+            <artifactId>directory-maven-plugin</artifactId>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+    <profile>
+      <id>demo</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-dependency-plugin</artifactId>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+</project>
\ No newline at end of file
diff --git a/saga-demo/saga-servicecomb-demo/scb-booking/pom.xml b/saga-demo/saga-servicecomb-demo/scb-booking/pom.xml
new file mode 100644
index 00000000..4a21c108
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-booking/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>saga-servicecomb-demo</artifactId>
+    <groupId>org.apache.servicecomb.saga.demo</groupId>
+    <version>0.3.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>scb-booking</artifactId>
+  <name>Saga::Demo::ServiceComb-Demo::Booking</name>
+
+</project>
\ No newline at end of file
diff --git a/saga-demo/saga-servicecomb-demo/scb-booking/src/main/java/org/apache/servicecomb/saga/demo/scb/booking/BookingApplication.java b/saga-demo/saga-servicecomb-demo/scb-booking/src/main/java/org/apache/servicecomb/saga/demo/scb/booking/BookingApplication.java
new file mode 100644
index 00000000..bc243376
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-booking/src/main/java/org/apache/servicecomb/saga/demo/scb/booking/BookingApplication.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.saga.demo.scb.booking;
+
+import org.apache.servicecomb.saga.omega.spring.EnableOmega;
+import org.apache.servicecomb.springboot.starter.provider.EnableServiceComb;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+@EnableServiceComb
+@EnableOmega
+public class BookingApplication {
+  public static void main(String[] args) {
+    SpringApplication.run(BookingApplication.class, args);
+  }
+}
diff --git a/saga-demo/saga-servicecomb-demo/scb-booking/src/main/java/org/apache/servicecomb/saga/demo/scb/booking/BookingController.java b/saga-demo/saga-servicecomb-demo/scb-booking/src/main/java/org/apache/servicecomb/saga/demo/scb/booking/BookingController.java
new file mode 100644
index 00000000..cc6947b9
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-booking/src/main/java/org/apache/servicecomb/saga/demo/scb/booking/BookingController.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.saga.demo.scb.booking;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
+import org.apache.servicecomb.saga.omega.context.annotations.SagaStart;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
+
+@RestSchema(schemaId = "booking")
+@RequestMapping(path = "/")
+public class BookingController {
+
+  private RestTemplate template = RestTemplateBuilder.create();
+
+  @SagaStart
+  @PostMapping("/booking/{name}/{rooms}/{cars}")
+  public String order(@PathVariable String name,  @PathVariable Integer rooms, @PathVariable Integer cars) {
+    template.postForEntity(
+        "cse://car/order/{name}/{cars}",
+        null, String.class, name, cars);
+
+    template.postForEntity(
+        "cse://hotel/order/{name}/{rooms}",
+        null, String.class, name, rooms);
+
+    postBooking();
+
+    return name + " booking " + rooms + " rooms and " + cars + " cars OK";
+  }
+
+  // This method is used by the byteman to inject the faults such as the timeout or the crash
+  private void postBooking() {
+
+  }
+}
diff --git a/saga-demo/saga-servicecomb-demo/scb-booking/src/main/resources/application.yaml b/saga-demo/saga-servicecomb-demo/scb-booking/src/main/resources/application.yaml
new file mode 100644
index 00000000..65e6508b
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-booking/src/main/resources/application.yaml
@@ -0,0 +1,22 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+spring:
+  application:
+    name: booking
+alpha:
+  cluster:
+    address: alpha-server.servicecomb.io:8080
diff --git a/saga-demo/saga-servicecomb-demo/scb-booking/src/main/resources/log4j2.xml b/saga-demo/saga-servicecomb-demo/scb-booking/src/main/resources/log4j2.xml
new file mode 100644
index 00000000..cae04cb9
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-booking/src/main/resources/log4j2.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<Configuration status="WARN">
+  <Appenders>
+    <Console name="Console" target="SYSTEM_OUT">
+      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
+    </Console>
+  </Appenders>
+  <Loggers>
+    <AsyncRoot level="info">
+      <AppenderRef ref="Console"/>
+    </AsyncRoot>
+  </Loggers>
+</Configuration>
diff --git a/saga-demo/saga-servicecomb-demo/scb-booking/src/main/resources/microservice.yaml b/saga-demo/saga-servicecomb-demo/scb-booking/src/main/resources/microservice.yaml
new file mode 100644
index 00000000..60d9a7aa
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-booking/src/main/resources/microservice.yaml
@@ -0,0 +1,46 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+#More details can be found :
+# 1.http://servicecomb.incubator.apache.org/users/service-definition/
+# 2.http://servicecomb.incubator.apache.org/users/service-configurations/
+# 3.http://servicecomb.incubator.apache.org/users/communicate-protocol/
+
+#Indicates an application name
+APPLICATION_ID: demo
+service_description:
+#Indicates a microservice name
+#The microservice name should be unique within an application.
+#The name can contain digits, uppercase and lowercase letters, hyphens(-), underscores(_), and periods(.); and can neither start nor end with punctuations.
+#The naming rule is as follows: ^[a-zA-Z0-9]+$|^[a-zA-Z0-9][a-zA-Z0-9_-.]*[a-zA-Z0-9]$.
+  name: booking
+#Indicates a service version
+  version: 1.0.0
+servicecomb:
+  service:
+  #Specifies the service center IP address.
+    registry:
+      address: http://service-center.servicecomb.io:30100
+  #Specifies the rest transport listening IP address.
+  rest:
+    address: 0.0.0.0:8083
+
+  #Add Saga Handler
+  handler:
+    chain:
+      Consumer:
+        default: loadbalance,saga-consumer
\ No newline at end of file
diff --git a/saga-demo/saga-servicecomb-demo/scb-car/pom.xml b/saga-demo/saga-servicecomb-demo/scb-car/pom.xml
new file mode 100644
index 00000000..8f13b373
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-car/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>saga-servicecomb-demo</artifactId>
+    <groupId>org.apache.servicecomb.saga.demo</groupId>
+    <version>0.3.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>scb-car</artifactId>
+  <name>Saga::Demo::ServiceComb-Demo::Car</name>
+
+</project>
\ No newline at end of file
diff --git a/saga-demo/saga-servicecomb-demo/scb-car/src/main/java/org/apache/servicecomb/saga/demo/scb/car/CarApplication.java b/saga-demo/saga-servicecomb-demo/scb-car/src/main/java/org/apache/servicecomb/saga/demo/scb/car/CarApplication.java
new file mode 100644
index 00000000..435168db
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-car/src/main/java/org/apache/servicecomb/saga/demo/scb/car/CarApplication.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.saga.demo.scb.car;
+
+import org.apache.servicecomb.saga.omega.spring.EnableOmega;
+import org.apache.servicecomb.springboot.starter.provider.EnableServiceComb;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+@EnableServiceComb
+@EnableOmega
+public class CarApplication {
+  public static void main(String[] args) {
+    SpringApplication.run(CarApplication.class, args);
+  }
+}
diff --git a/saga-demo/saga-servicecomb-demo/scb-car/src/main/java/org/apache/servicecomb/saga/demo/scb/car/CarBooking.java b/saga-demo/saga-servicecomb-demo/scb-car/src/main/java/org/apache/servicecomb/saga/demo/scb/car/CarBooking.java
new file mode 100644
index 00000000..497f278d
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-car/src/main/java/org/apache/servicecomb/saga/demo/scb/car/CarBooking.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.saga.demo.scb.car;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+@JsonAutoDetect(fieldVisibility = Visibility.ANY)
+class CarBooking {
+  @JsonIgnore
+  private Integer id;
+  private String name;
+  private Integer amount;
+  private boolean confirmed;
+  private boolean cancelled;
+
+  Integer getId() {
+    return id;
+  }
+
+  void setId(Integer id) {
+    this.id = id;
+  }
+
+  String getName() {
+    return name;
+  }
+
+  void setName(String name) {
+    this.name = name;
+  }
+
+  Integer getAmount() {
+    return amount;
+  }
+
+  void setAmount(Integer amount) {
+    this.amount = amount;
+  }
+
+  boolean isConfirmed() {
+    return confirmed;
+  }
+
+  void confirm() {
+    this.confirmed = true;
+    this.cancelled = false;
+  }
+
+  boolean isCancelled() {
+    return cancelled;
+  }
+
+  void cancel() {
+    this.confirmed = false;
+    this.cancelled = true;
+  }
+}
diff --git a/saga-demo/saga-servicecomb-demo/scb-car/src/main/java/org/apache/servicecomb/saga/demo/scb/car/CarBookingController.java b/saga-demo/saga-servicecomb-demo/scb-car/src/main/java/org/apache/servicecomb/saga/demo/scb/car/CarBookingController.java
new file mode 100644
index 00000000..35ff1467
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-car/src/main/java/org/apache/servicecomb/saga/demo/scb/car/CarBookingController.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.saga.demo.scb.car;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@RestSchema(schemaId = "car")
+@RequestMapping(path = "/")
+public class CarBookingController {
+  @Autowired
+  private CarBookingService service;
+
+  private final AtomicInteger id = new AtomicInteger(0);
+
+  @CrossOrigin
+  @GetMapping(path = "/bookings")
+  public List<CarBooking> getAll() {
+    return new ArrayList<>(service.getAllBookings());
+  }
+
+  @PostMapping(path = "/order/{name}/{cars}")
+  public CarBooking order(@PathVariable String name, @PathVariable Integer cars) {
+    CarBooking booking = new CarBooking();
+    booking.setId(id.incrementAndGet());
+    booking.setName(name);
+    booking.setAmount(cars);
+    service.order(booking);
+    return booking;
+  }
+
+  @DeleteMapping(path = "/bookings")
+  void clear() {
+    service.clearAllBookings();
+    id.set(0);
+  }
+}
diff --git a/saga-demo/saga-servicecomb-demo/scb-car/src/main/java/org/apache/servicecomb/saga/demo/scb/car/CarBookingService.java b/saga-demo/saga-servicecomb-demo/scb-car/src/main/java/org/apache/servicecomb/saga/demo/scb/car/CarBookingService.java
new file mode 100644
index 00000000..a94cf098
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-car/src/main/java/org/apache/servicecomb/saga/demo/scb/car/CarBookingService.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.saga.demo.scb.car;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.servicecomb.saga.omega.transaction.annotations.Compensable;
+import org.springframework.stereotype.Service;
+
+@Service
+class CarBookingService {
+  private Map<Integer, CarBooking> bookings = new ConcurrentHashMap<>();
+
+  @Compensable(compensationMethod = "cancel")
+  void order(CarBooking booking) {
+    booking.confirm();
+    bookings.put(booking.getId(), booking);
+  }
+
+  void cancel(CarBooking booking) {
+    Integer id = booking.getId();
+    if (bookings.containsKey(id)) {
+      bookings.get(id).cancel();
+    }
+  }
+
+  Collection<CarBooking> getAllBookings() {
+    return bookings.values();
+  }
+
+  void clearAllBookings() {
+    bookings.clear();
+  }
+}
diff --git a/saga-demo/saga-servicecomb-demo/scb-car/src/main/resources/application.yaml b/saga-demo/saga-servicecomb-demo/scb-car/src/main/resources/application.yaml
new file mode 100644
index 00000000..42572f30
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-car/src/main/resources/application.yaml
@@ -0,0 +1,22 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+spring:
+  application:
+    name: car
+alpha:
+  cluster:
+    address: alpha-server.servicecomb.io:8080
diff --git a/saga-demo/saga-servicecomb-demo/scb-car/src/main/resources/log4j2.xml b/saga-demo/saga-servicecomb-demo/scb-car/src/main/resources/log4j2.xml
new file mode 100644
index 00000000..cae04cb9
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-car/src/main/resources/log4j2.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<Configuration status="WARN">
+  <Appenders>
+    <Console name="Console" target="SYSTEM_OUT">
+      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
+    </Console>
+  </Appenders>
+  <Loggers>
+    <AsyncRoot level="info">
+      <AppenderRef ref="Console"/>
+    </AsyncRoot>
+  </Loggers>
+</Configuration>
diff --git a/saga-demo/saga-servicecomb-demo/scb-car/src/main/resources/microservice.yaml b/saga-demo/saga-servicecomb-demo/scb-car/src/main/resources/microservice.yaml
new file mode 100644
index 00000000..49aab59b
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-car/src/main/resources/microservice.yaml
@@ -0,0 +1,46 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+#More details can be found :
+# 1.http://servicecomb.incubator.apache.org/users/service-definition/
+# 2.http://servicecomb.incubator.apache.org/users/service-configurations/
+# 3.http://servicecomb.incubator.apache.org/users/communicate-protocol/
+
+#Indicates an application name
+APPLICATION_ID: demo
+service_description:
+#Indicates a microservice name
+#The microservice name should be unique within an application.
+#The name can contain digits, uppercase and lowercase letters, hyphens(-), underscores(_), and periods(.); and can neither start nor end with punctuations.
+#The naming rule is as follows: ^[a-zA-Z0-9]+$|^[a-zA-Z0-9][a-zA-Z0-9_-.]*[a-zA-Z0-9]$.
+  name: car
+#Indicates a service version
+  version: 1.0.0
+servicecomb:
+  service:
+  #Specifies the service center IP address.
+    registry:
+      address: http://service-center.servicecomb.io:30100
+  #Specifies the rest transport listening IP address.
+  rest:
+    address: 0.0.0.0:8082
+
+  #Add Saga Handler
+  handler:
+    chain:
+      Provider:
+        default: saga-provider
\ No newline at end of file
diff --git a/saga-demo/saga-servicecomb-demo/scb-hotel/pom.xml b/saga-demo/saga-servicecomb-demo/scb-hotel/pom.xml
new file mode 100644
index 00000000..b617d4d4
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-hotel/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>saga-servicecomb-demo</artifactId>
+    <groupId>org.apache.servicecomb.saga.demo</groupId>
+    <version>0.3.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>scb-hotel</artifactId>
+  <name>Saga::Demo::ServiceComb-Demo::Hotel</name>
+
+</project>
\ No newline at end of file
diff --git a/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/java/org/apache/servicecomb/saga/demo/scb/hotel/HotelApplication.java b/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/java/org/apache/servicecomb/saga/demo/scb/hotel/HotelApplication.java
new file mode 100644
index 00000000..ce8c0cbc
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/java/org/apache/servicecomb/saga/demo/scb/hotel/HotelApplication.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.saga.demo.scb.hotel;
+
+import org.apache.servicecomb.saga.omega.spring.EnableOmega;
+import org.apache.servicecomb.springboot.starter.provider.EnableServiceComb;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+@EnableServiceComb
+@EnableOmega
+public class HotelApplication {
+  public static void main(String[] args) {
+    SpringApplication.run(HotelApplication.class, args);
+  }
+}
diff --git a/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/java/org/apache/servicecomb/saga/demo/scb/hotel/HotelBooking.java b/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/java/org/apache/servicecomb/saga/demo/scb/hotel/HotelBooking.java
new file mode 100644
index 00000000..b183a793
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/java/org/apache/servicecomb/saga/demo/scb/hotel/HotelBooking.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.saga.demo.scb.hotel;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+@JsonAutoDetect(fieldVisibility = Visibility.ANY)
+class HotelBooking {
+  @JsonIgnore
+  private Integer id;
+  private String name;
+  private Integer amount;
+  private boolean confirmed;
+  private boolean cancelled;
+
+  Integer getId() {
+    return id;
+  }
+
+  void setId(Integer id) {
+    this.id = id;
+  }
+
+  String getName() {
+    return name;
+  }
+
+  void setName(String name) {
+    this.name = name;
+  }
+
+  Integer getAmount() {
+    return amount;
+  }
+
+  void setAmount(Integer amount) {
+    this.amount = amount;
+  }
+
+  boolean isConfirmed() {
+    return confirmed;
+  }
+
+  void confirm() {
+    this.confirmed = true;
+    this.cancelled = false;
+  }
+
+  boolean isCancelled() {
+    return cancelled;
+  }
+
+  void cancel() {
+    this.confirmed = false;
+    this.cancelled = true;
+  }
+}
diff --git a/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/java/org/apache/servicecomb/saga/demo/scb/hotel/HotelBookingController.java b/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/java/org/apache/servicecomb/saga/demo/scb/hotel/HotelBookingController.java
new file mode 100644
index 00000000..d7d3cd37
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/java/org/apache/servicecomb/saga/demo/scb/hotel/HotelBookingController.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.saga.demo.scb.hotel;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@RestSchema(schemaId = "hotel")
+@RequestMapping(path = "/")
+public class HotelBookingController {
+  @Autowired
+  private HotelBookingService service;
+
+  private final AtomicInteger id = new AtomicInteger(0);
+
+  @CrossOrigin
+  @GetMapping(path = "/bookings")
+  public List<HotelBooking> getAll() {
+    return new ArrayList<>(service.getAllBookings());
+  }
+
+  @PostMapping(path = "/order/{name}/{rooms}")
+  public HotelBooking order(@PathVariable String name, @PathVariable Integer rooms) {
+    HotelBooking booking = new HotelBooking();
+    booking.setId(id.incrementAndGet());
+    booking.setName(name);
+    booking.setAmount(rooms);
+    service.order(booking);
+    return booking;
+  }
+
+  @DeleteMapping(path = "/bookings")
+  public void clear() {
+    service.clearAllBookings();
+    id.set(0);
+  }
+}
diff --git a/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/java/org/apache/servicecomb/saga/demo/scb/hotel/HotelBookingService.java b/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/java/org/apache/servicecomb/saga/demo/scb/hotel/HotelBookingService.java
new file mode 100644
index 00000000..4d4d5500
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/java/org/apache/servicecomb/saga/demo/scb/hotel/HotelBookingService.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.saga.demo.scb.hotel;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.servicecomb.saga.omega.transaction.annotations.Compensable;
+import org.springframework.stereotype.Service;
+
+@Service
+class HotelBookingService {
+  private Map<Integer, HotelBooking> bookings = new ConcurrentHashMap<>();
+
+  @Compensable(compensationMethod = "cancel")
+  void order(HotelBooking booking) {
+    if (booking.getAmount() > 2) {
+      throw new IllegalArgumentException("can not order the rooms large than two");
+    }
+    booking.confirm();
+    bookings.put(booking.getId(), booking);
+  }
+
+  void cancel(HotelBooking booking) {
+    Integer id = booking.getId();
+    if (bookings.containsKey(id)) {
+      bookings.get(id).cancel();
+    }
+  }
+
+  Collection<HotelBooking> getAllBookings() {
+    return bookings.values();
+  }
+
+  void clearAllBookings() {
+    bookings.clear();
+  }
+}
diff --git a/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/resources/application.yaml b/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/resources/application.yaml
new file mode 100644
index 00000000..99bb4a8b
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/resources/application.yaml
@@ -0,0 +1,22 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+spring:
+  application:
+    name: hotel
+alpha:
+  cluster:
+    address: alpha-server.servicecomb.io:8080
diff --git a/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/resources/log4j2.xml b/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/resources/log4j2.xml
new file mode 100644
index 00000000..cae04cb9
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/resources/log4j2.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<Configuration status="WARN">
+  <Appenders>
+    <Console name="Console" target="SYSTEM_OUT">
+      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
+    </Console>
+  </Appenders>
+  <Loggers>
+    <AsyncRoot level="info">
+      <AppenderRef ref="Console"/>
+    </AsyncRoot>
+  </Loggers>
+</Configuration>
diff --git a/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/resources/microservice.yaml b/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/resources/microservice.yaml
new file mode 100644
index 00000000..0ac5dbac
--- /dev/null
+++ b/saga-demo/saga-servicecomb-demo/scb-hotel/src/main/resources/microservice.yaml
@@ -0,0 +1,46 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+#More details can be found :
+# 1.http://servicecomb.incubator.apache.org/users/service-definition/
+# 2.http://servicecomb.incubator.apache.org/users/service-configurations/
+# 3.http://servicecomb.incubator.apache.org/users/communicate-protocol/
+
+#Indicates an application name
+APPLICATION_ID: demo
+service_description:
+#Indicates a microservice name
+#The microservice name should be unique within an application.
+#The name can contain digits, uppercase and lowercase letters, hyphens(-), underscores(_), and periods(.); and can neither start nor end with punctuations.
+#The naming rule is as follows: ^[a-zA-Z0-9]+$|^[a-zA-Z0-9][a-zA-Z0-9_-.]*[a-zA-Z0-9]$.
+  name: hotel
+#Indicates a service version
+  version: 1.0.0
+servicecomb:
+  service:
+  #Specifies the service center IP address.
+    registry:
+      address: http://service-center.servicecomb.io:30100
+  #Specifies the rest transport listening IP address.
+  rest:
+    address: 0.0.0.0:8081
+
+  #Add Saga Handler
+  handler:
+    chain:
+      Provider:
+        default: saga-provider
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services