You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2018/05/28 08:26:29 UTC
[incubator-servicecomb-saga] 01/13: SCB-555 Add saga-dubbo-demo It
also shows verify the error of SCB-547 click 7.[A.run->B.run,
B.run->C.run(x), C.run exception],
and org.apache.servicecomb.saga.alpha.core.EventScanner.pollEvents scheduler
will stop running. TODO: add acceptance test (cucumber)
This is an automated email from the ASF dual-hosted git repository.
ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-saga.git
commit 189edeb507367be9bc469b99a6ff2fb2f1a9a5f2
Author: wuzunqian <wu...@msn.com>
AuthorDate: Sun May 6 01:09:23 2018 +0800
SCB-555 Add saga-dubbo-demo
It also shows verify the error of SCB-547
click 7.[A.run->B.run, B.run->C.run(x), C.run exception], and org.apache.servicecomb.saga.alpha.core.EventScanner.pollEvents scheduler will stop running.
TODO: add acceptance test (cucumber)
---
.../omega-transport/omega-transport-dubbo/pom.xml | 6 +-
saga-demo/saga-dubbo-demo/README.md | 28 ++++
saga-demo/saga-dubbo-demo/pom.xml | 116 +++++++++++++++
.../saga-dubbo-demo/service-api}/pom.xml | 30 ++--
.../servicecomb/saga/demo/dubbo/api/IService.java | 26 ++++
.../servicecomb/saga/demo/dubbo/api/IServiceA.java | 21 +++
.../servicecomb/saga/demo/dubbo/api/IServiceB.java | 22 +++
.../servicecomb/saga/demo/dubbo/api/IServiceC.java | 22 +++
.../src/main/resources/dubbo.properties | 18 +++
.../saga-dubbo-demo/service-pub}/pom.xml | 23 +--
.../saga/demo/dubbo/pub/AbsService.java | 39 +++++
.../saga/demo/dubbo/pub/IInvokeCode.java | 39 +++++
.../saga/demo/dubbo/pub/InvokeContext.java | 56 ++++++++
.../saga-dubbo-demo/servicea}/pom.xml | 30 ++--
.../saga/demo/dubbo/servicea/ApplicationA.java | 31 ++++
.../saga/demo/dubbo/servicea/ServiceA.java | 78 ++++++++++
.../dubbo/servicea/web/DubboDemoController.java | 157 +++++++++++++++++++++
.../demo/dubbo/servicea/web/MvcConfigurer.java | 39 +++++
.../servicea/src/main/resources/application.yaml | 23 +++
.../servicea/src/main/resources/dubbo-context.xml | 31 ++++
.../servicea/src/main/resources/jdbc.xml | 58 ++++++++
.../servicea/src/main/resources/log4j2.xml | 30 ++++
.../servicea/src/main/resources/static/index.html | 42 ++++++
.../saga-dubbo-demo/serviceb}/pom.xml | 30 ++--
.../saga/demo/dubbo/serviceb/ApplicationB.java | 32 +++++
.../saga/demo/dubbo/serviceb/ServiceB.java | 69 +++++++++
.../serviceb/src/main/resources/application.yaml | 22 +++
.../serviceb/src/main/resources/dubbo-context.xml | 30 ++++
.../serviceb/src/main/resources/jdbc.xml | 57 ++++++++
.../serviceb/src/main/resources/log4j2.xml | 30 ++++
.../saga-dubbo-demo/servicec}/pom.xml | 30 ++--
.../saga/demo/dubbo/servicec/ApplicationC.java | 31 ++++
.../saga/demo/dubbo/servicec/ServiceC.java | 61 ++++++++
.../servicec/src/main/resources/application.yaml | 22 +++
.../servicec/src/main/resources/dubbo-context.xml | 28 ++++
.../servicec/src/main/resources/jdbc.xml | 57 ++++++++
.../servicec/src/main/resources/log4j2.xml | 30 ++++
saga-demo/saga-dubbo-demo/sql/schema-mysql.sql | 43 ++++++
38 files changed, 1449 insertions(+), 88 deletions(-)
diff --git a/omega/omega-transport/omega-transport-dubbo/pom.xml b/omega/omega-transport/omega-transport-dubbo/pom.xml
index 65893c4..0830266 100644
--- a/omega/omega-transport/omega-transport-dubbo/pom.xml
+++ b/omega/omega-transport/omega-transport-dubbo/pom.xml
@@ -27,12 +27,16 @@
</parent>
<modelVersion>4.0.0</modelVersion>
+ <properties>
+ <dubbo.version>2.6.1</dubbo.version>
+ </properties>
+
<artifactId>omega-transport-dubbo</artifactId>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
- <version>2.6.1</version>
+ <version>${dubbo.version}</version>
</dependency>
<dependency>
diff --git a/saga-demo/saga-dubbo-demo/README.md b/saga-demo/saga-dubbo-demo/README.md
new file mode 100644
index 0000000..86ecbf6
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/README.md
@@ -0,0 +1,28 @@
+# Saga-dubbo-demo
+This demo including three services:
+* servicea
+* serviceb
+* servicec
+
+## Prerequisites
+You will need:
+1. [JDK 1.8][jdk]
+2. [Maven 3.x][maven]
+3. [alpha server][alpha_server]
+
+[jdk]: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
+[maven]: https://maven.apache.org/install.html
+[alpha_server]: https://github.com/apache/incubator-servicecomb-saga/tree/master/alpha
+
+## Running Demo
+you can run saga-dubbo-demo as normal spring application
+1.init database: sql/schema-mysql.sql, and config database info by enviroment params
+enviroment params example:
+-Ddatabase.url=jdbc:mysql://127.0.0.1:3306/saga_dubbo
+-Ddatabase.username=root
+-Ddatabase.password=***
+-Dzookeeper.url=localhost:2181
+-Dserver.port=8071
+
+2.config zookeeper url by enviroment param
+3.run servicea, serviceb, servicec,visit http://${servicea_host}:${servicea_port}
\ No newline at end of file
diff --git a/saga-demo/saga-dubbo-demo/pom.xml b/saga-demo/saga-dubbo-demo/pom.xml
new file mode 100644
index 0000000..634cd69
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/pom.xml
@@ -0,0 +1,116 @@
+<?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.2.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>saga-dubbo-demo</artifactId>
+ <name>Saga::Demo::Saga-dubbo-demo</name>
+ <packaging>pom</packaging>
+
+ <properties>
+ <saga.version>0.2.0-SNAPSHOT</saga.version>
+ </properties>
+
+ <modules>
+ <module>service-api</module>
+ <module>servicea</module>
+ <module>serviceb</module>
+ <module>servicec</module>
+ <module>service-pub</module>
+ </modules>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${spring.boot.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>${maven-dependency-plugin.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb.saga</groupId>
+ <artifactId>omega-transport-dubbo</artifactId>
+ <version>${saga.version} </version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb.saga</groupId>
+ <artifactId>omega-spring-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</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-resttemplate</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.github.sgroschupf</groupId>
+ <artifactId>zkclient</artifactId>
+ <version>0.1</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>log4j</artifactId>
+ <groupId>log4j</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-dbcp2</artifactId>
+ <version>2.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.37</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/omega/omega-transport/omega-transport-dubbo/pom.xml b/saga-demo/saga-dubbo-demo/service-api/pom.xml
similarity index 73%
copy from omega/omega-transport/omega-transport-dubbo/pom.xml
copy to saga-demo/saga-dubbo-demo/service-api/pom.xml
index 65893c4..1347a47 100644
--- a/omega/omega-transport/omega-transport-dubbo/pom.xml
+++ b/saga-demo/saga-dubbo-demo/service-api/pom.xml
@@ -14,33 +14,31 @@
~ 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>omega-transport</artifactId>
- <groupId>org.apache.servicecomb.saga</groupId>
- <version>0.2.0-SNAPSHOT</version>
- </parent>
<modelVersion>4.0.0</modelVersion>
-
- <artifactId>omega-transport-dubbo</artifactId>
<dependencies>
<dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>dubbo</artifactId>
- <version>2.6.1</version>
+ <groupId>org.apache.servicecomb.saga.demo</groupId>
+ <artifactId>service-pub</artifactId>
</dependency>
-
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <scope>test</scope>
+ <groupId>org.apache.servicecomb.saga.demo</groupId>
+ <artifactId>service-pub</artifactId>
+ <version>0.2.0-SNAPSHOT</version>
+ <scope>compile</scope>
</dependency>
</dependencies>
+ <parent>
+ <artifactId>saga-dubbo-demo</artifactId>
+ <groupId>org.apache.servicecomb.saga.demo</groupId>
+ <version>0.2.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>service-api</artifactId>
-</project>
+</project>
\ No newline at end of file
diff --git a/saga-demo/saga-dubbo-demo/service-api/src/main/java/org/apache/servicecomb/saga/demo/dubbo/api/IService.java b/saga-demo/saga-dubbo-demo/service-api/src/main/java/org/apache/servicecomb/saga/demo/dubbo/api/IService.java
new file mode 100644
index 0000000..1269981
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/service-api/src/main/java/org/apache/servicecomb/saga/demo/dubbo/api/IService.java
@@ -0,0 +1,26 @@
+/*
+ * 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.dubbo.api;
+
+import org.apache.servicecomb.saga.demo.dubbo.pub.InvokeContext;
+
+public interface IService {
+
+ public Object run(InvokeContext invokeContext) throws Exception;
+ public void cancelRun(InvokeContext invokeContext);
+
+}
diff --git a/saga-demo/saga-dubbo-demo/service-api/src/main/java/org/apache/servicecomb/saga/demo/dubbo/api/IServiceA.java b/saga-demo/saga-dubbo-demo/service-api/src/main/java/org/apache/servicecomb/saga/demo/dubbo/api/IServiceA.java
new file mode 100644
index 0000000..17ab38d
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/service-api/src/main/java/org/apache/servicecomb/saga/demo/dubbo/api/IServiceA.java
@@ -0,0 +1,21 @@
+/*
+ * 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.dubbo.api;
+
+public interface IServiceA extends IService{
+
+}
diff --git a/saga-demo/saga-dubbo-demo/service-api/src/main/java/org/apache/servicecomb/saga/demo/dubbo/api/IServiceB.java b/saga-demo/saga-dubbo-demo/service-api/src/main/java/org/apache/servicecomb/saga/demo/dubbo/api/IServiceB.java
new file mode 100644
index 0000000..15f734d
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/service-api/src/main/java/org/apache/servicecomb/saga/demo/dubbo/api/IServiceB.java
@@ -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.
+ */
+package org.apache.servicecomb.saga.demo.dubbo.api;
+
+import java.util.Map;
+
+public interface IServiceB extends IService{
+}
diff --git a/saga-demo/saga-dubbo-demo/service-api/src/main/java/org/apache/servicecomb/saga/demo/dubbo/api/IServiceC.java b/saga-demo/saga-dubbo-demo/service-api/src/main/java/org/apache/servicecomb/saga/demo/dubbo/api/IServiceC.java
new file mode 100644
index 0000000..ef5acb8
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/service-api/src/main/java/org/apache/servicecomb/saga/demo/dubbo/api/IServiceC.java
@@ -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.
+ */
+package org.apache.servicecomb.saga.demo.dubbo.api;
+
+import java.util.Map;
+
+public interface IServiceC extends IService{
+}
diff --git a/saga-demo/saga-dubbo-demo/service-api/src/main/resources/dubbo.properties b/saga-demo/saga-dubbo-demo/service-api/src/main/resources/dubbo.properties
new file mode 100644
index 0000000..b86f300
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/service-api/src/main/resources/dubbo.properties
@@ -0,0 +1,18 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+dubbo.application.qos.enable=false
+dubbo.application.qos.port=33333
\ No newline at end of file
diff --git a/omega/omega-transport/omega-transport-dubbo/pom.xml b/saga-demo/saga-dubbo-demo/service-pub/pom.xml
similarity index 68%
copy from omega/omega-transport/omega-transport-dubbo/pom.xml
copy to saga-demo/saga-dubbo-demo/service-pub/pom.xml
index 65893c4..1ca1310 100644
--- a/omega/omega-transport/omega-transport-dubbo/pom.xml
+++ b/saga-demo/saga-dubbo-demo/service-pub/pom.xml
@@ -14,33 +14,18 @@
~ 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>omega-transport</artifactId>
- <groupId>org.apache.servicecomb.saga</groupId>
+ <artifactId>saga-dubbo-demo</artifactId>
+ <groupId>org.apache.servicecomb.saga.demo</groupId>
<version>0.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>omega-transport-dubbo</artifactId>
- <dependencies>
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>dubbo</artifactId>
- <version>2.6.1</version>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <artifactId>service-pub</artifactId>
-</project>
+</project>
\ No newline at end of file
diff --git a/saga-demo/saga-dubbo-demo/service-pub/src/main/java/org/apache/servicecomb/saga/demo/dubbo/pub/AbsService.java b/saga-demo/saga-dubbo-demo/service-pub/src/main/java/org/apache/servicecomb/saga/demo/dubbo/pub/AbsService.java
new file mode 100644
index 0000000..16f5608
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/service-pub/src/main/java/org/apache/servicecomb/saga/demo/dubbo/pub/AbsService.java
@@ -0,0 +1,39 @@
+/*
+ * 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.dubbo.pub;
+
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.util.Map;
+
+public abstract class AbsService {
+
+ @javax.annotation.Resource(name = "jdbcTemplate")
+ protected JdbcTemplate jdbcTemplate;
+
+ public abstract String getServiceName();
+ public abstract String getTableName();
+
+ protected void doRunBusi() {
+ this.jdbcTemplate.update(String.format("update %s set vstatus=? where service = ?", getTableName()), "run", getServiceName());
+ }
+
+ protected void doCancelBusi() {
+ this.jdbcTemplate.update(String.format("update %s set vstatus=? where service = ?", getTableName()), "cancel", getServiceName());
+ }
+
+}
diff --git a/saga-demo/saga-dubbo-demo/service-pub/src/main/java/org/apache/servicecomb/saga/demo/dubbo/pub/IInvokeCode.java b/saga-demo/saga-dubbo-demo/service-pub/src/main/java/org/apache/servicecomb/saga/demo/dubbo/pub/IInvokeCode.java
new file mode 100644
index 0000000..b7153ac
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/service-pub/src/main/java/org/apache/servicecomb/saga/demo/dubbo/pub/IInvokeCode.java
@@ -0,0 +1,39 @@
+/*
+ * 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.dubbo.pub;
+
+/**
+ * a invoke code describe a test scenario
+* @date 05/05/2018 3:27 PM
+*/
+public interface IInvokeCode {
+
+ public static final String Ab_description="A->B, success";
+ public static final String Ab = "Ab";
+ public static final String AExceptionWhenAb_description="A->B, A.run exception after A call B.run";
+ public static final String AExceptionWhenAb="AExceptionWhenAb";
+ public static final String BExceptionWhenAb_description="A->B, B.run exception";
+ public static final String BExceptionWhenAb="BExceptionWhenAb";
+ public static final String AbAc_description="A->B, A->C success";
+ public static final String AbAc="AbAc";
+ public static final String CExceptionWhenAbAc_description="A->B,A->C, C.run exception";
+ public static final String CExceptionWhenAbAc="CExceptionWhenAbAc";
+ public static final String AbBc_description="A->B, B->C, success";
+ public static final String AbBc="AbBc";
+ public static final String CExceptionWhenAbBc_description="A->B, B->C, C.run exception";
+ public static final String CExceptionWhenAbBc="CExceptionWhenAbBc";
+}
diff --git a/saga-demo/saga-dubbo-demo/service-pub/src/main/java/org/apache/servicecomb/saga/demo/dubbo/pub/InvokeContext.java b/saga-demo/saga-dubbo-demo/service-pub/src/main/java/org/apache/servicecomb/saga/demo/dubbo/pub/InvokeContext.java
new file mode 100644
index 0000000..8225447
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/service-pub/src/main/java/org/apache/servicecomb/saga/demo/dubbo/pub/InvokeContext.java
@@ -0,0 +1,56 @@
+/*
+ * 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.dubbo.pub;
+
+public class InvokeContext implements java.io.Serializable{
+
+ private String invokeCode;
+
+ public String getInvokeCode() {
+ return invokeCode;
+ }
+
+ public InvokeContext setInvokeCode(String invokeCode) {
+ this.invokeCode = invokeCode;
+ return this;
+ }
+
+ public boolean isInvokeB(String serviceName) {
+ return "servicea".equals(serviceName) && (IInvokeCode.AExceptionWhenAb.equals(invokeCode)
+ || IInvokeCode.Ab.equals(invokeCode)
+ || IInvokeCode.BExceptionWhenAb.equals(invokeCode)
+ || IInvokeCode.AbAc.equals(invokeCode)
+ || IInvokeCode.CExceptionWhenAbAc.equals(invokeCode)
+ || IInvokeCode.AbBc.equals(invokeCode)
+ || IInvokeCode.CExceptionWhenAbBc.equals(invokeCode));
+ }
+
+ public boolean isInvokeC(String serviceName) {
+ return ("serviceb".equals(serviceName) && IInvokeCode.AbBc.equals(invokeCode))
+ || ("serviceb".equals(serviceName) && IInvokeCode.CExceptionWhenAbBc.equals(invokeCode))
+ || ("servicea".equals(serviceName) && IInvokeCode.AbAc.equals(invokeCode))
+ || ("servicea".equals(serviceName) && IInvokeCode.CExceptionWhenAbAc.equals(invokeCode));
+ }
+
+ public boolean isException(String serviceName) {
+ return ("servicea".equals(serviceName) && IInvokeCode.AExceptionWhenAb.equals(invokeCode))
+ || ("serviceb".equals(serviceName) && IInvokeCode.BExceptionWhenAb.equals(invokeCode))
+ || ("servicec".equals(serviceName) && (IInvokeCode.CExceptionWhenAbAc.equals(invokeCode)
+ || IInvokeCode.CExceptionWhenAbBc.equals(invokeCode)));
+ }
+
+}
diff --git a/omega/omega-transport/omega-transport-dubbo/pom.xml b/saga-demo/saga-dubbo-demo/servicea/pom.xml
similarity index 73%
copy from omega/omega-transport/omega-transport-dubbo/pom.xml
copy to saga-demo/saga-dubbo-demo/servicea/pom.xml
index 65893c4..1360034 100644
--- a/omega/omega-transport/omega-transport-dubbo/pom.xml
+++ b/saga-demo/saga-dubbo-demo/servicea/pom.xml
@@ -14,33 +14,31 @@
~ 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>omega-transport</artifactId>
- <groupId>org.apache.servicecomb.saga</groupId>
- <version>0.2.0-SNAPSHOT</version>
- </parent>
<modelVersion>4.0.0</modelVersion>
-
- <artifactId>omega-transport-dubbo</artifactId>
<dependencies>
<dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>dubbo</artifactId>
- <version>2.6.1</version>
+ <groupId>org.apache.servicecomb.saga.demo</groupId>
+ <artifactId>service-api</artifactId>
+ <version>${saga.version}</version>
</dependency>
-
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <scope>test</scope>
+ <groupId>org.apache.servicecomb.saga.demo</groupId>
+ <artifactId>service-pub</artifactId>
+ <version>${saga.version}</version>
</dependency>
</dependencies>
+ <parent>
+ <groupId>org.apache.servicecomb.saga.demo</groupId>
+ <artifactId>saga-dubbo-demo</artifactId>
+ <version>0.2.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servicea</artifactId>
-</project>
+</project>
\ No newline at end of file
diff --git a/saga-demo/saga-dubbo-demo/servicea/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicea/ApplicationA.java b/saga-demo/saga-dubbo-demo/servicea/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicea/ApplicationA.java
new file mode 100644
index 0000000..ace9358
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicea/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicea/ApplicationA.java
@@ -0,0 +1,31 @@
+/*
+ * 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.dubbo.servicea;
+import org.apache.servicecomb.saga.omega.spring.EnableOmega;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.ImportResource;
+
+@SpringBootApplication
+@EnableOmega
+@ImportResource({"dubbo-context.xml", "jdbc.xml"})
+public class ApplicationA {
+ public static void main(String[] args) {
+ SpringApplication.run(ApplicationA.class, args);
+ }
+}
diff --git a/saga-demo/saga-dubbo-demo/servicea/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicea/ServiceA.java b/saga-demo/saga-dubbo-demo/servicea/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicea/ServiceA.java
new file mode 100644
index 0000000..dad5259
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicea/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicea/ServiceA.java
@@ -0,0 +1,78 @@
+/*
+ * 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.dubbo.servicea;
+
+import org.apache.servicecomb.saga.demo.dubbo.api.IServiceA;
+import org.apache.servicecomb.saga.demo.dubbo.api.IServiceB;
+import org.apache.servicecomb.saga.demo.dubbo.api.IServiceC;
+import org.apache.servicecomb.saga.demo.dubbo.pub.AbsService;
+import org.apache.servicecomb.saga.demo.dubbo.pub.InvokeContext;
+import org.apache.servicecomb.saga.omega.context.annotations.SagaStart;
+import org.apache.servicecomb.saga.omega.transaction.annotations.Compensable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.lang.invoke.MethodHandles;
+
+public class ServiceA extends AbsService implements IServiceA {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ @Autowired
+ private IServiceB serviceB;
+
+ @Autowired
+ private IServiceC serviceC;
+
+ @Override
+ public String getServiceName() {
+ return "servicea";
+ }
+
+ @Override
+ public String getTableName() {
+ return "testa";
+ }
+
+ @Override
+ @SagaStart
+ @Compensable( compensationMethod="cancelRun")
+ @Transactional(rollbackFor = Exception.class)
+ public Object run(InvokeContext invokeContext) throws Exception {
+ LOG.info("A.run called");
+ doRunBusi();
+ if(invokeContext.isInvokeB(getServiceName())){
+ serviceB.run(invokeContext);
+ }
+ if(invokeContext.isInvokeC(getServiceName())){
+ serviceC.run(invokeContext);
+ }
+ if(invokeContext.isException(getServiceName()) ){
+ LOG.info("A.run exception");
+ throw new Exception("A.run exception");
+ }
+ return null;
+ }
+
+ public void cancelRun(InvokeContext invokeContext){
+ LOG.info("A.cancel called");
+ doCancelBusi();
+ }
+
+}
diff --git a/saga-demo/saga-dubbo-demo/servicea/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicea/web/DubboDemoController.java b/saga-demo/saga-dubbo-demo/servicea/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicea/web/DubboDemoController.java
new file mode 100644
index 0000000..c2c9eb3
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicea/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicea/web/DubboDemoController.java
@@ -0,0 +1,157 @@
+/*
+ * 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.dubbo.servicea.web;
+
+import org.apache.servicecomb.saga.demo.dubbo.api.IServiceA;
+import org.apache.servicecomb.saga.demo.dubbo.pub.IInvokeCode;
+import org.apache.servicecomb.saga.demo.dubbo.pub.InvokeContext;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class DubboDemoController {
+
+ @Autowired
+ private IServiceA serviceA;
+
+ @javax.annotation.Resource(name = "jdbcTemplate")
+ protected JdbcTemplate jdbcTemplate;
+
+
+ @GetMapping("/serviceInvoke/Ab")
+ public String serviceInvokeAb() throws Exception {
+ serviceInvoke(IInvokeCode.Ab);
+ String status_a = getServiceStatus("testa");
+ String status_b = getServiceStatus("testb");
+ boolean checkResult = checkResult("run", status_a, "run", status_b);
+ return String.format(IInvokeCode.Ab_description +
+ "</br>check result: %s" +
+ "</br>expected status: A:run, B:run" +
+ "</br> actual status: A:%s, B:%s", checkResult, status_a, status_b);
+ }
+
+ private boolean checkResult(String... statusArray) {
+ for(int i=0; i<statusArray.length; i++){
+ if(i%2==0 && i<statusArray.length){
+ if(!statusArray[i].equals(statusArray[i+1])) return false;
+ }
+ }
+ return true;
+ }
+
+ @GetMapping("/serviceInvoke/AExceptionWhenAb")
+ public String serviceInvokeAExceptionWhenAb() throws Exception {
+ serviceInvoke(IInvokeCode.AExceptionWhenAb);
+ String status_a = getServiceStatus("testa");
+ String status_b = getServiceStatus("testb");
+ boolean checkResult = checkResult("init", status_a, "cancel", status_b);
+ return String.format(IInvokeCode.AExceptionWhenAb_description +
+ "</br>check result: %s" +
+ "</br>expected status: A:init, B:cancel" +
+ "</br> actual status: A:%s, B:%s", checkResult, status_a, status_b);
+ }
+
+ @GetMapping("/serviceInvoke/BExceptionWhenAb")
+ public String serviceInvokeBExceptionWhenAb() throws Exception {
+ serviceInvoke(IInvokeCode.BExceptionWhenAb);
+ String status_a = getServiceStatus("testa");
+ String status_b = getServiceStatus("testb");
+ boolean checkResult = checkResult("init", status_a, "init", status_b);
+ return String.format(IInvokeCode.BExceptionWhenAb_description +
+ "</br>check result: %s" +
+ "</br>expected status: A:init, B:init" +
+ "</br> actual status: A:%s, B:%s", checkResult, status_a, status_b);
+ }
+
+ @GetMapping("/serviceInvoke/AbAc")
+ public String serviceInvokeAbAc() throws Exception {
+ serviceInvoke(IInvokeCode.AbAc);
+ String status_a = getServiceStatus("testa");
+ String status_b = getServiceStatus("testb");
+ String status_c = getServiceStatus("testc");
+ boolean checkResult = checkResult("run", status_a, "run", status_b, "run", status_c);
+ return String.format(IInvokeCode.AbAc_description +
+ "</br>check result: %s" +
+ "</br>expected status: A:run, B:run, C:run" +
+ "</br> actual status: A:%s, B:%s, C: %s", checkResult, status_a, status_b, status_c);
+ }
+
+ @GetMapping("/serviceInvoke/CExceptionWhenAbAc")
+ public String serviceInvokeCExceptionWhenAbAc() throws Exception {
+ serviceInvoke(IInvokeCode.CExceptionWhenAbAc);
+ String status_a = getServiceStatus("testa");
+ String status_b = getServiceStatus("testb");
+ String status_c = getServiceStatus("testc");
+ boolean checkResult = checkResult("init", status_a, "init", status_b, "init", status_c);
+ return String.format(IInvokeCode.CExceptionWhenAbAc_description +
+ "</br>check result: %s" +
+ "</br>expected status: A:init, B:init, C:init" +
+ "</br> actual status: A:%s, B:%s, C: %s", checkResult, status_a, status_b, status_c);
+ }
+
+ @GetMapping("/serviceInvoke/AbBc")
+ public String serviceInvokeAbBc() throws Exception {
+ serviceInvoke(IInvokeCode.AbBc);
+ String status_a = getServiceStatus("testa");
+ String status_b = getServiceStatus("testb");
+ String status_c = getServiceStatus("testc");
+ boolean checkResult = checkResult("run", status_a, "run", status_b, "run", status_c);
+ return String.format(IInvokeCode.AbBc_description +
+ "</br>check result: %s" +
+ "</br>expected status: A:run, B:run, C:run" +
+ "</br> actual status: A:%s, B:%s, C: %s", checkResult, status_a, status_b, status_c);
+ }
+
+ @GetMapping("/serviceInvoke/CExceptionWhenAbBc")
+ public String serviceInvokeCExceptionWhenAbBc() throws Exception {
+ serviceInvoke(IInvokeCode.CExceptionWhenAbBc);
+ String status_a = getServiceStatus("testa");
+ String status_b = getServiceStatus("testb");
+ String status_c = getServiceStatus("testc");
+ boolean checkResult = checkResult("init", status_a, "init", status_b, "init", status_c);
+ return String.format(IInvokeCode.CExceptionWhenAbBc_description +
+ "</br>check result: %s" +
+ "</br>expected status: A:init, B:init, C:init" +
+ "</br> actual status: A:%s, B:%s, C: %s", checkResult, status_a, status_b, status_c);
+ }
+
+ public void serviceInvoke(String invokeCode) throws InterruptedException {
+ reset();
+ try{
+ serviceA.run(new InvokeContext().setInvokeCode(invokeCode));
+ }catch (Exception e){
+ e.printStackTrace();
+ //wait for compensate execute
+ Thread.sleep(1000);
+ }
+
+ }
+
+ public void reset() {
+ this.jdbcTemplate.update("update testa set vstatus=? ", "init");
+ this.jdbcTemplate.update("update testb set vstatus=? ", "init");
+ this.jdbcTemplate.update("update testc set vstatus=? ", "init");
+ }
+
+ public String getServiceStatus(String tableName){
+ return this.jdbcTemplate.queryForObject(String.format("select vstatus from %s", tableName), String.class);
+ }
+
+}
diff --git a/saga-demo/saga-dubbo-demo/servicea/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicea/web/MvcConfigurer.java b/saga-demo/saga-dubbo-demo/servicea/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicea/web/MvcConfigurer.java
new file mode 100644
index 0000000..d815f60
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicea/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicea/web/MvcConfigurer.java
@@ -0,0 +1,39 @@
+/*
+ * 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.dubbo.servicea.web;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.Ordered;
+import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+@Configuration
+public class MvcConfigurer extends WebMvcConfigurerAdapter {
+
+ @Override
+ public void addViewControllers(ViewControllerRegistry registry) {
+ registry.addViewController("/error").setViewName("error.html");
+ registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
+ }
+
+ @Override
+ public void configurePathMatch(PathMatchConfigurer configurer) {
+ super.configurePathMatch(configurer);
+ configurer.setUseSuffixPatternMatch(false);
+ }
+}
\ No newline at end of file
diff --git a/saga-demo/saga-dubbo-demo/servicea/src/main/resources/application.yaml b/saga-demo/saga-dubbo-demo/servicea/src/main/resources/application.yaml
new file mode 100644
index 0000000..3880847
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicea/src/main/resources/application.yaml
@@ -0,0 +1,23 @@
+## ---------------------------------------------------------------------------
+## 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: servicea
+alpha:
+ cluster:
+ address: localhost:8080
+
diff --git a/saga-demo/saga-dubbo-demo/servicea/src/main/resources/dubbo-context.xml b/saga-demo/saga-dubbo-demo/servicea/src/main/resources/dubbo-context.xml
new file mode 100644
index 0000000..1c73e90
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicea/src/main/resources/dubbo-context.xml
@@ -0,0 +1,31 @@
+<?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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
+ <dubbo:application name="dubbo-servicea"/>
+ <dubbo:consumer check="false" timeout="10000" />
+ <!--localhost:2181-->
+ <dubbo:registry address="zookeeper://${zookeeper.url}?client=zkclient"/>
+ <dubbo:protocol name="dubbo" port="20881"/>
+ <dubbo:service interface="org.apache.servicecomb.saga.demo.dubbo.api.IServiceA" ref="servicea"/>
+ <bean id="servicea" class="org.apache.servicecomb.saga.demo.dubbo.servicea.ServiceA"/>
+ <dubbo:reference id="serviceb" interface="org.apache.servicecomb.saga.demo.dubbo.api.IServiceB"/>
+ <dubbo:reference id="servicec" interface="org.apache.servicecomb.saga.demo.dubbo.api.IServiceC"/>
+</beans>
\ No newline at end of file
diff --git a/saga-demo/saga-dubbo-demo/servicea/src/main/resources/jdbc.xml b/saga-demo/saga-dubbo-demo/servicea/src/main/resources/jdbc.xml
new file mode 100644
index 0000000..001ee81
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicea/src/main/resources/jdbc.xml
@@ -0,0 +1,58 @@
+<?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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd
+ http://www.springframework.org/schema/aop
+ http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+ http://www.springframework.org/schema/tx
+ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
+
+ <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
+ <property name="driverClassName" value="com.mysql.jdbc.Driver" />
+ <!--jdbc:mysql://127.0.0.1:3306/saga_dubbo-->
+ <property name="url" value="${database.url}" />
+ <property name="username" value="${database.username}" />
+ <property name="password" value="${database.password}" />
+ <property name="maxTotal" value="50" />
+ <property name="initialSize" value="20" />
+ <property name="maxWaitMillis" value="60000" />
+ <property name="minIdle" value="6" />
+ <property name="logAbandoned" value="true" />
+ <property name="removeAbandonedOnMaintenance" value="true" />
+ <property name="removeAbandonedOnBorrow" value="true" />
+ <property name="removeAbandonedTimeout" value="1800" />
+
+ <property name="testWhileIdle" value="true" />
+ <property name="testOnBorrow" value="false" />
+ <property name="testOnReturn" value="false" />
+ <property name="validationQuery" value="select 'x' " />
+ <property name="validationQueryTimeout" value="1" />
+ <property name="timeBetweenEvictionRunsMillis" value="30000" />
+ <property name="numTestsPerEvictionRun" value="20" />
+ </bean>
+
+ <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
+ <property name="dataSource" ref="dataSource" />
+ </bean>
+
+</beans>
diff --git a/saga-demo/saga-dubbo-demo/servicea/src/main/resources/log4j2.xml b/saga-demo/saga-dubbo-demo/servicea/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..eb57a2d
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicea/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="debug">
+ <AppenderRef ref="Console"/>
+ </AsyncRoot>
+ </Loggers>
+</Configuration>
diff --git a/saga-demo/saga-dubbo-demo/servicea/src/main/resources/static/index.html b/saga-demo/saga-dubbo-demo/servicea/src/main/resources/static/index.html
new file mode 100644
index 0000000..f366003
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicea/src/main/resources/static/index.html
@@ -0,0 +1,42 @@
+<!--
+ ~ 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.
+ -->
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta charset="utf-8">
+ <title>saga-dubbo-demo</title>
+ <meta name="description" content="">
+ <meta name="author" content="">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" href="">
+ <!--[if lt IE 9]>
+ <script src="//cdn.jsdelivr.net/html5shiv/3.7.2/html5shiv.min.js"></script>
+ <script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
+ <![endif]-->
+ <link rel="shortcut icon" href="">
+</head>
+<body>
+<p>1.<a href="/serviceInvoke/Ab" target="_blank">[A.run->B.run, success]</a> </p>
+<p>2.<a href="/serviceInvoke/AExceptionWhenAb" target="_blank">[A.run(x)->B.run, A.run exception after call B.run]</a> </p>
+<p>3.<a href="/serviceInvoke/BExceptionWhenAb" target="_blank">[A.run->B.run(x), B.run exception]</a> </p>
+<p>4.<a href="/serviceInvoke/AbAc" target="_blank">[A.run->B.run, A.run->C.run, success]</a> </p>
+<p>5.<a href="/serviceInvoke/CExceptionWhenAbAc" target="_blank">[A.run->B.run, A.run->C.run(x), C.run exception]</a> </p>
+<p>6.<a href="/serviceInvoke/AbBc" target="_blank">[A.run->B.run, B.run->C.run, success]</a></p>
+<p>7.<a href="/serviceInvoke/CExceptionWhenAbBc" target="_blank">[A.run->B.run, B.run->C.run(x), C.run exception]</a> </p>
+</body>
+</html>
\ No newline at end of file
diff --git a/omega/omega-transport/omega-transport-dubbo/pom.xml b/saga-demo/saga-dubbo-demo/serviceb/pom.xml
similarity index 73%
copy from omega/omega-transport/omega-transport-dubbo/pom.xml
copy to saga-demo/saga-dubbo-demo/serviceb/pom.xml
index 65893c4..bbfceb6 100644
--- a/omega/omega-transport/omega-transport-dubbo/pom.xml
+++ b/saga-demo/saga-dubbo-demo/serviceb/pom.xml
@@ -14,33 +14,27 @@
~ 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>omega-transport</artifactId>
- <groupId>org.apache.servicecomb.saga</groupId>
- <version>0.2.0-SNAPSHOT</version>
- </parent>
<modelVersion>4.0.0</modelVersion>
-
- <artifactId>omega-transport-dubbo</artifactId>
<dependencies>
<dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>dubbo</artifactId>
- <version>2.6.1</version>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <scope>test</scope>
+ <groupId>org.apache.servicecomb.saga.demo</groupId>
+ <artifactId>service-api</artifactId>
+ <version>0.2.0-SNAPSHOT</version>
+ <scope>compile</scope>
</dependency>
</dependencies>
+ <parent>
+ <groupId>org.apache.servicecomb.saga.demo</groupId>
+ <artifactId>saga-dubbo-demo</artifactId>
+ <version>0.2.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>serviceb</artifactId>
-</project>
+</project>
\ No newline at end of file
diff --git a/saga-demo/saga-dubbo-demo/serviceb/src/main/java/org/apache/servicecomb/saga/demo/dubbo/serviceb/ApplicationB.java b/saga-demo/saga-dubbo-demo/serviceb/src/main/java/org/apache/servicecomb/saga/demo/dubbo/serviceb/ApplicationB.java
new file mode 100644
index 0000000..e31c375
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/serviceb/src/main/java/org/apache/servicecomb/saga/demo/dubbo/serviceb/ApplicationB.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.dubbo.serviceb;
+
+import org.apache.servicecomb.saga.omega.spring.EnableOmega;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ImportResource;
+
+@SpringBootApplication
+@EnableOmega
+@ImportResource({"dubbo-context.xml", "jdbc.xml"})
+public class ApplicationB {
+ public static void main(String[] args) {
+ SpringApplication.run(ApplicationB.class, args);
+ }
+}
diff --git a/saga-demo/saga-dubbo-demo/serviceb/src/main/java/org/apache/servicecomb/saga/demo/dubbo/serviceb/ServiceB.java b/saga-demo/saga-dubbo-demo/serviceb/src/main/java/org/apache/servicecomb/saga/demo/dubbo/serviceb/ServiceB.java
new file mode 100644
index 0000000..0c7890f
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/serviceb/src/main/java/org/apache/servicecomb/saga/demo/dubbo/serviceb/ServiceB.java
@@ -0,0 +1,69 @@
+/*
+ * 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.dubbo.serviceb;
+
+import org.apache.servicecomb.saga.demo.dubbo.api.IServiceB;
+import org.apache.servicecomb.saga.demo.dubbo.api.IServiceC;
+import org.apache.servicecomb.saga.demo.dubbo.pub.AbsService;
+import org.apache.servicecomb.saga.demo.dubbo.pub.InvokeContext;
+import org.apache.servicecomb.saga.omega.transaction.annotations.Compensable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.lang.invoke.MethodHandles;
+
+public class ServiceB extends AbsService implements IServiceB {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ @Autowired
+ private IServiceC serviceC;
+
+ @Override
+ public String getServiceName() {
+ return "serviceb";
+ }
+
+ @Override
+ public String getTableName() {
+ return "testb";
+ }
+
+ @Override
+ @Compensable( compensationMethod="cancelRun")
+ @Transactional(rollbackFor = Exception.class)
+ public Object run(InvokeContext invokeContext) throws Exception {
+ LOG.info("B.run called");
+ doRunBusi();
+ if(invokeContext.isInvokeC(getServiceName())){
+ serviceC.run(invokeContext);
+ }
+ if(invokeContext.isException(getServiceName())){
+ throw new Exception("B.run exception");
+ }
+
+ return null;
+ }
+
+ public void cancelRun(InvokeContext invokeContext){
+ LOG.info("B.cancel called");
+ doCancelBusi();
+ }
+
+}
diff --git a/saga-demo/saga-dubbo-demo/serviceb/src/main/resources/application.yaml b/saga-demo/saga-dubbo-demo/serviceb/src/main/resources/application.yaml
new file mode 100644
index 0000000..f78027a
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/serviceb/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: serviceb
+alpha:
+ cluster:
+ address: localhost:8080
diff --git a/saga-demo/saga-dubbo-demo/serviceb/src/main/resources/dubbo-context.xml b/saga-demo/saga-dubbo-demo/serviceb/src/main/resources/dubbo-context.xml
new file mode 100644
index 0000000..519900e
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/serviceb/src/main/resources/dubbo-context.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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
+ <dubbo:application name="dubbo-serviceb"/>
+ <dubbo:consumer check="false" timeout="10000" />
+ <!--localhost:2181-->
+ <dubbo:registry address="zookeeper://${zookeeper.url}?client=zkclient"/>
+ <dubbo:protocol name="dubbo" port="20882"/>
+ <dubbo:service interface="org.apache.servicecomb.saga.demo.dubbo.api.IServiceB" ref="serviceb"/>
+ <bean id="serviceb" class="org.apache.servicecomb.saga.demo.dubbo.serviceb.ServiceB"/>
+ <dubbo:reference id="servicec" interface="org.apache.servicecomb.saga.demo.dubbo.api.IServiceC"/>
+</beans>
\ No newline at end of file
diff --git a/saga-demo/saga-dubbo-demo/serviceb/src/main/resources/jdbc.xml b/saga-demo/saga-dubbo-demo/serviceb/src/main/resources/jdbc.xml
new file mode 100644
index 0000000..3bdafa1
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/serviceb/src/main/resources/jdbc.xml
@@ -0,0 +1,57 @@
+<?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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd
+ http://www.springframework.org/schema/aop
+ http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+ http://www.springframework.org/schema/tx
+ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
+
+ <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
+ <property name="driverClassName" value="com.mysql.jdbc.Driver" />
+ <property name="url" value="${database.url}" />
+ <property name="username" value="${database.username}" />
+ <property name="password" value="${database.password}" />
+ <property name="maxTotal" value="50" />
+ <property name="initialSize" value="20" />
+ <property name="maxWaitMillis" value="60000" />
+ <property name="minIdle" value="6" />
+ <property name="logAbandoned" value="true" />
+ <property name="removeAbandonedOnMaintenance" value="true" />
+ <property name="removeAbandonedOnBorrow" value="true" />
+ <property name="removeAbandonedTimeout" value="1800" />
+
+ <property name="testWhileIdle" value="true" />
+ <property name="testOnBorrow" value="false" />
+ <property name="testOnReturn" value="false" />
+ <property name="validationQuery" value="select 'x' " />
+ <property name="validationQueryTimeout" value="1" />
+ <property name="timeBetweenEvictionRunsMillis" value="30000" />
+ <property name="numTestsPerEvictionRun" value="20" />
+ </bean>
+
+ <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
+ <property name="dataSource" ref="dataSource" />
+ </bean>
+
+</beans>
diff --git a/saga-demo/saga-dubbo-demo/serviceb/src/main/resources/log4j2.xml b/saga-demo/saga-dubbo-demo/serviceb/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..eb57a2d
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/serviceb/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="debug">
+ <AppenderRef ref="Console"/>
+ </AsyncRoot>
+ </Loggers>
+</Configuration>
diff --git a/omega/omega-transport/omega-transport-dubbo/pom.xml b/saga-demo/saga-dubbo-demo/servicec/pom.xml
similarity index 73%
copy from omega/omega-transport/omega-transport-dubbo/pom.xml
copy to saga-demo/saga-dubbo-demo/servicec/pom.xml
index 65893c4..79cdd4d 100644
--- a/omega/omega-transport/omega-transport-dubbo/pom.xml
+++ b/saga-demo/saga-dubbo-demo/servicec/pom.xml
@@ -14,33 +14,27 @@
~ 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>omega-transport</artifactId>
- <groupId>org.apache.servicecomb.saga</groupId>
- <version>0.2.0-SNAPSHOT</version>
- </parent>
<modelVersion>4.0.0</modelVersion>
-
- <artifactId>omega-transport-dubbo</artifactId>
<dependencies>
<dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>dubbo</artifactId>
- <version>2.6.1</version>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <scope>test</scope>
+ <groupId>org.apache.servicecomb.saga.demo</groupId>
+ <artifactId>service-api</artifactId>
+ <version>0.2.0-SNAPSHOT</version>
+ <scope>compile</scope>
</dependency>
</dependencies>
+ <parent>
+ <groupId>org.apache.servicecomb.saga.demo</groupId>
+ <artifactId>saga-dubbo-demo</artifactId>
+ <version>0.2.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servicec</artifactId>
-</project>
+</project>
\ No newline at end of file
diff --git a/saga-demo/saga-dubbo-demo/servicec/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicec/ApplicationC.java b/saga-demo/saga-dubbo-demo/servicec/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicec/ApplicationC.java
new file mode 100644
index 0000000..4fdfe25
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicec/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicec/ApplicationC.java
@@ -0,0 +1,31 @@
+/*
+ * 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.dubbo.servicec;
+import org.apache.servicecomb.saga.omega.spring.EnableOmega;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.ImportResource;
+
+@SpringBootApplication
+@EnableOmega
+@ImportResource({"dubbo-context.xml", "jdbc.xml"})
+public class ApplicationC {
+ public static void main(String[] args) {
+ SpringApplication.run(ApplicationC.class, args);
+ }
+}
diff --git a/saga-demo/saga-dubbo-demo/servicec/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicec/ServiceC.java b/saga-demo/saga-dubbo-demo/servicec/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicec/ServiceC.java
new file mode 100644
index 0000000..1f8d63e
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicec/src/main/java/org/apache/servicecomb/saga/demo/dubbo/servicec/ServiceC.java
@@ -0,0 +1,61 @@
+/*
+ * 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.dubbo.servicec;
+
+import org.apache.servicecomb.saga.demo.dubbo.api.IServiceC;
+import org.apache.servicecomb.saga.demo.dubbo.pub.AbsService;
+import org.apache.servicecomb.saga.demo.dubbo.pub.InvokeContext;
+import org.apache.servicecomb.saga.omega.transaction.annotations.Compensable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.lang.invoke.MethodHandles;
+
+public class ServiceC extends AbsService implements IServiceC {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ @Override
+ public String getServiceName() {
+ return "servicec";
+ }
+
+ @Override
+ public String getTableName() {
+ return "testc";
+ }
+
+ @Override
+ @Compensable(compensationMethod="cancelRun")
+ @Transactional(rollbackFor = Exception.class)
+ public Object run(InvokeContext invokeContext) throws Exception {
+ LOG.info("C.run called");
+ doRunBusi();
+ if(invokeContext.isException(getServiceName()) ){
+ LOG.info("C.run exception");
+ throw new Exception("C.run exception");
+ }
+ return null;
+ }
+
+ public void cancelRun(InvokeContext invokeContext){
+ LOG.info("C.cancel called");
+ doCancelBusi();
+ }
+
+}
diff --git a/saga-demo/saga-dubbo-demo/servicec/src/main/resources/application.yaml b/saga-demo/saga-dubbo-demo/servicec/src/main/resources/application.yaml
new file mode 100644
index 0000000..0535557
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicec/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: servicec
+alpha:
+ cluster:
+ address: localhost:8080
diff --git a/saga-demo/saga-dubbo-demo/servicec/src/main/resources/dubbo-context.xml b/saga-demo/saga-dubbo-demo/servicec/src/main/resources/dubbo-context.xml
new file mode 100644
index 0000000..b37d8a4
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicec/src/main/resources/dubbo-context.xml
@@ -0,0 +1,28 @@
+<?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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
+ <dubbo:application name="dubbo-servicec"/>
+ <!--localhost:2181-->
+ <dubbo:registry address="zookeeper://${zookeeper.url}?client=zkclient"/>
+ <dubbo:protocol name="dubbo" port="20883"/>
+ <dubbo:service interface="org.apache.servicecomb.saga.demo.dubbo.api.IServiceC" ref="servicec"/>
+ <bean id="servicec" class="org.apache.servicecomb.saga.demo.dubbo.servicec.ServiceC"/>
+</beans>
\ No newline at end of file
diff --git a/saga-demo/saga-dubbo-demo/servicec/src/main/resources/jdbc.xml b/saga-demo/saga-dubbo-demo/servicec/src/main/resources/jdbc.xml
new file mode 100644
index 0000000..3bdafa1
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicec/src/main/resources/jdbc.xml
@@ -0,0 +1,57 @@
+<?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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd
+ http://www.springframework.org/schema/aop
+ http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+ http://www.springframework.org/schema/tx
+ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
+
+ <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
+ <property name="driverClassName" value="com.mysql.jdbc.Driver" />
+ <property name="url" value="${database.url}" />
+ <property name="username" value="${database.username}" />
+ <property name="password" value="${database.password}" />
+ <property name="maxTotal" value="50" />
+ <property name="initialSize" value="20" />
+ <property name="maxWaitMillis" value="60000" />
+ <property name="minIdle" value="6" />
+ <property name="logAbandoned" value="true" />
+ <property name="removeAbandonedOnMaintenance" value="true" />
+ <property name="removeAbandonedOnBorrow" value="true" />
+ <property name="removeAbandonedTimeout" value="1800" />
+
+ <property name="testWhileIdle" value="true" />
+ <property name="testOnBorrow" value="false" />
+ <property name="testOnReturn" value="false" />
+ <property name="validationQuery" value="select 'x' " />
+ <property name="validationQueryTimeout" value="1" />
+ <property name="timeBetweenEvictionRunsMillis" value="30000" />
+ <property name="numTestsPerEvictionRun" value="20" />
+ </bean>
+
+ <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
+ <property name="dataSource" ref="dataSource" />
+ </bean>
+
+</beans>
diff --git a/saga-demo/saga-dubbo-demo/servicec/src/main/resources/log4j2.xml b/saga-demo/saga-dubbo-demo/servicec/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..eb57a2d
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/servicec/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="debug">
+ <AppenderRef ref="Console"/>
+ </AsyncRoot>
+ </Loggers>
+</Configuration>
diff --git a/saga-demo/saga-dubbo-demo/sql/schema-mysql.sql b/saga-demo/saga-dubbo-demo/sql/schema-mysql.sql
new file mode 100644
index 0000000..d9d0743
--- /dev/null
+++ b/saga-demo/saga-dubbo-demo/sql/schema-mysql.sql
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+create database saga_dubbo;
+use saga_dubbo;
+
+CREATE TABLE `testa` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `service` varchar(128) DEFAULT NULL,
+ `vstatus` varchar(128) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
+INSERT INTO `testa` (`id`, `service`, `vstatus`) VALUES ('1','servicea','init');
+
+CREATE TABLE `testb` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `service` varchar(128) DEFAULT NULL,
+ `vstatus` varchar(128) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
+INSERT INTO `testb` (`id`, `service`, `vstatus`) VALUES ('2','serviceb','init');
+
+CREATE TABLE `testc` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `service` varchar(128) DEFAULT NULL,
+ `vstatus` varchar(128) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
+INSERT INTO `testc` (`id`, `service`, `vstatus`) VALUES ('3','servicec','init');
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
ningjiang@apache.org.