项目重构

This commit is contained in:
yu.xiao 2018-03-02 11:58:32 +08:00
parent 899f42ed00
commit 471f172ec3
31 changed files with 0 additions and 2083 deletions

View File

@ -1,111 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>happylifeplat-transaction-tx-springcloud-sample</artifactId>
<groupId>com.happylifeplat.transaction</groupId>
<version>1.1.0-RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>happylifeplat-transaction-tx-springcloud-sample-alipay</artifactId>
<dependencies>
<dependency>
<groupId>com.happylifeplat.transaction</groupId>
<artifactId>happylifeplat-transaction-tx-springcloud</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<!--spring boot的核心启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--aop支持-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!--自动配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.29</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,45 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.alipay;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.ImportResource;
/**
* @author xiaoyu
*/
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
@EnableEurekaClient
@EnableFeignClients
@ImportResource({"classpath:applicationContext.xml"})
@MapperScan("com.happylifeplat.transaction.tx.springcloud.sample.alipay.mapper")
public class AliPayApplication {
public static void main(String[] args) {
SpringApplication.run(AliPayApplication.class, args);
}
}

View File

@ -1,69 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.alipay.controller;
import com.happylifeplat.transaction.tx.springcloud.sample.alipay.entity.Alipay;
import com.happylifeplat.transaction.tx.springcloud.sample.alipay.service.AlipayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author xiaoyu
*/
@RestController
@RequestMapping("/alipay")
public class AlipayController {
private final AlipayService alipayService;
@Autowired
public AlipayController(AlipayService alipayService) {
this.alipayService = alipayService;
}
@RequestMapping("/save")
public int save() {
Alipay alipay = new Alipay();
alipay.setAmount(BigDecimal.valueOf(100));
alipay.setName("ali");
alipay.setCreateTime(new Date());
return alipayService.payment(alipay);
}
@RequestMapping("/payFail")
public void payFail() {
alipayService.payFail();
}
@RequestMapping("/payTimeOut")
public void payTimeOut() {
Alipay alipay = new Alipay();
alipay.setAmount(BigDecimal.valueOf(100));
alipay.setName("ali");
alipay.setCreateTime(new Date());
alipayService.payTimeOut(alipay);
}
}

View File

@ -1,71 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.alipay.entity;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author xiaoyu
*/
public class Alipay {
private Integer id;
private String name;
/**
* 金额
*/
private BigDecimal amount;
private Date createTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}

View File

@ -1,39 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.alipay.mapper;
import com.happylifeplat.transaction.tx.springcloud.sample.alipay.entity.Alipay;
import org.apache.ibatis.annotations.Insert;
/**
* @author xiaoyu
*/
public interface AlipayMapper {
/**
* 数据库保存操作
*
* @param alipay 实体类
* @return rows
*/
@Insert("INSERT INTO alipay(name,amount,create_time) VALUES(#{name}, #{amount},#{createTime})")
int save(Alipay alipay);
}

View File

@ -1,46 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.alipay.service;
import com.happylifeplat.transaction.tx.springcloud.sample.alipay.entity.Alipay;
/**
* @author xiaoyu
*/
public interface AlipayService {
/**
* 付款动作
*
* @param alipay 实体类
* @return rows
*/
int payment(Alipay alipay);
/**
* 支付失败测试
*/
void payFail();
/**
* 支付超时
*
* @param alipay 实体类
*/
void payTimeOut(Alipay alipay);
}

View File

@ -1,67 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.alipay.service.impl;
import com.happylifeplat.transaction.core.annotation.TxTransaction;
import com.happylifeplat.transaction.tx.springcloud.sample.alipay.entity.Alipay;
import com.happylifeplat.transaction.tx.springcloud.sample.alipay.mapper.AlipayMapper;
import com.happylifeplat.transaction.tx.springcloud.sample.alipay.service.AlipayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author xiaoyu
*/
@Service
public class AlipayServiceImpl implements AlipayService {
private final AlipayMapper alipayMapper;
@Autowired
public AlipayServiceImpl(AlipayMapper alipayMapper) {
this.alipayMapper = alipayMapper;
}
@Override
@TxTransaction
public int payment(Alipay alipay) {
return alipayMapper.save(alipay);
}
@Override
@TxTransaction
public void payFail() {
alipayMapper.save(null);
}
@Override
@TxTransaction
public void payTimeOut(Alipay alipay) {
alipayMapper.save(alipay);
try {
//模拟超时
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

View File

@ -1,32 +0,0 @@
server:
port: 8882
contextPath: /alipay-service
address: 0.0.0.0
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.1.68:3306/alipay?useUnicode=true&characterEncoding=utf8
username: xiaoyu
password: Wgj@555888
application:
name: alipay-service
mybatis:
type-aliases-package: com.happylifeplat.transaction.tx.springcloud.sample.alipay.entiy
#${random.int[9000,9999]}
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
alipay-service :
ribbon.NFLoadBalancerRuleClassName : com.netflix.loadbalancer.RandomRule
logging:
level:
root: info
com.happylifeplat.transaction.core : debug
path: "./logs"

View File

@ -1,93 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
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"
default-autowire="byName">
<context:component-scan base-package="com.happylifeplat.transaction.*"/>
<aop:aspectj-autoproxy expose-proxy="true"/>
<bean id="txTransactionBootstrap" class="com.happylifeplat.transaction.core.bootstrap.TxTransactionBootstrap">
<property name="txManagerUrl" value="http://192.168.1.132:8761"/>
<property name="serializer" value="kryo"/>
<property name="nettySerializer" value="kryo"/>
<property name="blockingQueueType" value="Linked"/>
<property name="compensation" value="true"/>
<property name="compensationCacheType" value="db"/>
<property name="txDbConfig">
<bean class="com.happylifeplat.transaction.common.config.TxDbConfig">
<property name="url"
value="jdbc:mysql://192.168.1.68:3306/tx?useUnicode=true&amp;characterEncoding=utf8"/>
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="username" value="xiaoyu"/>
<property name="password" value="Wgj@555888"/>
</bean>
</property>
</bean>
<!--
<property name="compensationCacheType" value="db"/>
<property name="txDbConfig">
<bean class="com.happylifeplat.transaction.common.config.TxDbConfig">
<property name="url"
value="jdbc:mysql://192.168.1.68:3306/tx?useUnicode=true&amp;characterEncoding=utf8"/>
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="password" value="Wgj@555888"/>
<property name="username" value="xiaoyu"/>
</bean>
</property>
<property name="compensationCacheType" value="redis"/>
<property name="txRedisConfig">
<bean class="com.happylifeplat.transaction.common.config.TxRedisConfig">
<property name="hostName"
value="192.168.1.68"/>
<property name="port" value="6379"/>
<property name="password" value=""/>
</bean>
</property>
<property name="compensationCacheType" value="zookeeper"/>
<property name="txZookeeperConfig">
<bean class="com.happylifeplat.transaction.common.config.TxZookeeperConfig">
<property name="host" value="192.168.1.132:2181"/>
<property name="sessionTimeOut" value="100000"/>
<property name="rootPath" value="/tx"/>
</bean>
</property>
<property name="compensationCacheType" value="mongodb"/>
<property name="txMongoConfig">
<bean class="com.happylifeplat.transaction.common.config.TxMongoConfig">
<property name="mongoDbUrl" value="192.168.1.68:27017"/>
<property name="mongoDbName" value="happylife"/>
<property name="mongoUserName" value="xiaoyu"/>
<property name="mongoUserPwd" value="123456"/>
</bean>
</property>
<property name="compensationCacheType" value="file"/>
<property name="txFileConfig">
<bean class="com.happylifeplat.transaction.common.config.TxFileConfig">
<property name="path" value=""/>
<property name="prefix" value="tx"/>
</bean>
</property>
-->
</beans>

View File

@ -1,125 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>happylifeplat-transaction-tx-springcloud-sample</artifactId>
<groupId>com.happylifeplat.transaction</groupId>
<version>1.1.0-RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>happylifeplat-transaction-tx-springcloud-sample-pay</artifactId>
<dependencies>
<dependency>
<groupId>com.happylifeplat.transaction</groupId>
<artifactId>happylifeplat-transaction-tx-springcloud</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<!--spring boot的核心启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--aop支持-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!--自动配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.29</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,45 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.pay;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.ImportResource;
/**
* @author xiaoyu
*/
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
@EnableEurekaClient
@EnableFeignClients
@ImportResource({"classpath:applicationContext.xml"})
@MapperScan("com.happylifeplat.transaction.tx.springcloud.sample.pay.mapper")
public class PayApplication {
public static void main(String[] args) {
SpringApplication.run(PayApplication.class, args);
}
}

View File

@ -1,48 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.pay.client;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author xiaoyu
*/
@FeignClient(value = "alipay-service", configuration = MyConfiguration.class)
public interface AlipayClient {
/**
* 保存操作
*
* @return rows
*/
@RequestMapping("/alipay-service/alipay/save")
int save();
/**
* 支付失败情况测试
*/
@RequestMapping("/alipay-service/alipay/payFail")
void payFail();
/**
* 支付超时情况测试
*/
@RequestMapping("/alipay-service/alipay/payTimeOut")
void payTimeOut();
}

View File

@ -1,49 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.pay.client;
import com.happylifeplat.transaction.tx.springcloud.feign.RestTemplateInterceptor;
import feign.Feign;
import feign.Request;
import feign.Retryer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
/**
* @author xiaoyu
*/
@Configuration
public class MyConfiguration {
@Bean
@Scope("prototype")
public Feign.Builder feignBuilder() {
return Feign.builder().requestInterceptor(new RestTemplateInterceptor());
}
@Bean
Request.Options feignOptions() {
return new Request.Options(5000, 5000);
}
@Bean
Retryer feignRetryer() {
return Retryer.NEVER_RETRY;
}
}

View File

@ -1,48 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.pay.client;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author xiaoyu
*/
@FeignClient(value = "wechat-service", configuration = MyConfiguration.class)
public interface WechatClient {
/**
* 保存
*
* @return rows
*/
@RequestMapping("/wechat-service/wechat/save")
int save();
/**
* 微信支付失败
*/
@RequestMapping("/wechat-service/wechat/payFail")
void payFail();
/**
* 微信支付超时
*/
@RequestMapping("/wechat-service/wechat/payTimeOut")
void payTimeOut();
}

View File

@ -1,73 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.pay.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ResponseMessageBuilder;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.time.LocalDate;
import static com.google.common.collect.Lists.newArrayList;
/**
* @author xiaoyu
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
private static final String SWAGGER_SCAN_BASE_PACKAGE = "com.happylifeplat.transaction.tx.springcloud.sample.pay.controller";
private static final String VERSION = "1.0.0";
ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Swagger API")
.description("springcloud分布式事务解决方案之二阶段提交测试体验")
.license("Apache 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
.termsOfServiceUrl("")
.version(VERSION)
.contact(new Contact("xiaoyu", "", "549477611@qq.com"))
.build();
}
// swagger
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
// .paths(paths())
.build().pathMapping("/").directModelSubstitute(LocalDate.class, String.class)
.genericModelSubstitutes(ResponseEntity.class).useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET, newArrayList(new ResponseMessageBuilder().code(500).message("500 message")
.responseModel(new ModelRef("Error")).build()));
}
}

View File

@ -1,105 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.pay.controller;
import com.happylifeplat.transaction.tx.springcloud.sample.pay.service.PayService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/**
* @author xiaoyu
*/
@RestController
@RequestMapping("/pay")
public class PayController {
private final PayService payService;
@Autowired
public PayController(PayService payService) {
this.payService = payService;
}
@PostMapping("/orderPay")
public String save() {
payService.orderPay();
return "success";
}
@PostMapping("/aliPayFail")
@ApiOperation("当alipay支付异常的时候pay表的数据不会新增 alipay表不会新增 wechat表不会新增")
public String aliPayFail() {
try {
payService.payWithAliPayFail();
} catch (Exception e) {
e.printStackTrace();
return "aili pay fail and pay not commit";
}
return "success";
}
@PostMapping("/aliPayTimeOut")
@ApiOperation("当alipay支付超时的时候pay表的数据不会新增 alipay表不会新增 wechat表不会新增")
public String aliPayTimeOut() {
try {
payService.payWithAliPayTimeOut();
} catch (Exception e) {
e.printStackTrace();
return "aili pay time out and pay not commit";
}
return "success";
}
@PostMapping("/wechatPayFail")
@ApiOperation("当wechat支付失败的时候pay表的数据不会新增 alipay表不会新增 wechat表不会新增")
public String wechatPayFail() {
try {
payService.payWithWechatPayFail();
} catch (Exception e) {
e.printStackTrace();
return "wechat pay fail : pay not commit,alipay not commit ";
}
return "success";
}
@PostMapping("/wechatPayTimeOut")
@ApiOperation("当wechat支付超时的时候pay表的数据不会新增 alipay表不会新增 wechat表不会新增")
public String wechatPayTimeOut() {
try {
payService.payWithWechatPayTimeOut();
} catch (Exception e) {
e.printStackTrace();
return "wechat pay time out : pay not commit,alipay not commit ";
}
return "success";
}
}

View File

@ -1,68 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.pay.entiy;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author xiaoyu
*/
public class Pay {
private Integer id;
private String name;
private BigDecimal totalAmount;
private Date createTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getTotalAmount() {
return totalAmount;
}
public void setTotalAmount(BigDecimal totalAmount) {
this.totalAmount = totalAmount;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}

View File

@ -1,38 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.pay.mapper;
import com.happylifeplat.transaction.tx.springcloud.sample.pay.entiy.Pay;
import org.apache.ibatis.annotations.Insert;
/**
* @author xiaoyu
*/
public interface PayMapper {
/**
* 保存支付信息
*
* @param pay 实体
* @return row 条数
*/
@Insert("INSERT INTO pay(name,total_amount,create_time) VALUES(#{name}, #{totalAmount},#{createTime})")
int save(Pay pay);
}

View File

@ -1,58 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.pay.service;
/**
* @author xiaoyu
*/
public interface PayService {
/**
* 正常支付 这时候 pay alipay wechat 表都会新增一条数据
*
* @return Boolean
*/
Boolean orderPay();
/**
* 强一致性测试 执行顺序 pay-->alipay-->wechat
* 当alipay支付异常的时候pay表的数据不会新增 alipay表不会新增 wechat表不会新增
*/
void payWithAliPayFail();
/**
* 强一致性测试 执行顺序 pay-->alipay-->wechat
* 当alipay支付超时的时候pay表的数据不会新增 alipay表不会新增 wechat表不会新增
*/
void payWithAliPayTimeOut();
/**
* 强一致性测试 执行顺序 pay-->alipay-->wechat
* 当wechat支付失败的时候pay表的数据不会新增 alipay表不会新增 wechat表不会新增
*/
void payWithWechatPayFail();
/**
* 强一致性测试 执行顺序 pay-->alipay-->wechat
* 当wechat支付超时的时候pay表的数据不会新增 alipay表不会新增 wechat表不会新增
*/
void payWithWechatPayTimeOut();
}

View File

@ -1,142 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.pay.service.impl;
import com.happylifeplat.transaction.core.annotation.TxTransaction;
import com.happylifeplat.transaction.tx.springcloud.sample.pay.client.AlipayClient;
import com.happylifeplat.transaction.tx.springcloud.sample.pay.client.WechatClient;
import com.happylifeplat.transaction.tx.springcloud.sample.pay.entiy.Pay;
import com.happylifeplat.transaction.tx.springcloud.sample.pay.mapper.PayMapper;
import com.happylifeplat.transaction.tx.springcloud.sample.pay.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author xiaoyu
*/
@Service
public class PayServiceImpl implements PayService {
private final AlipayClient alipayClient;
private final WechatClient wechatClient;
private final PayMapper payMapper;
@Autowired
public PayServiceImpl(AlipayClient alipayClient, WechatClient wechatClient, PayMapper payMapper) {
this.alipayClient = alipayClient;
this.wechatClient = wechatClient;
this.payMapper = payMapper;
}
@Override
@TxTransaction
public Boolean orderPay() {
Pay pay = new Pay();
pay.setName("ali|| wechat");
pay.setTotalAmount(BigDecimal.valueOf(200));
pay.setCreateTime(new Date());
payMapper.save(pay);
alipayClient.save();
wechatClient.save();
return true;
}
/**
* 强一致性测试 执行顺序 pay-->alipay-->wechat
* 当alipay支付异常的时候pay表的数据不会新增 alipay表不会新增 wechat表不会新增
*/
@Override
@TxTransaction
public void payWithAliPayFail() {
Pay pay = new Pay();
pay.setName("ali|| wechat");
pay.setTotalAmount(BigDecimal.valueOf(200));
pay.setCreateTime(new Date());
payMapper.save(pay);
alipayClient.payFail();
wechatClient.save();
}
/**
* 强一致性测试 执行顺序 pay-->alipay-->wechat
* 当alipay支付超时的时候pay表的数据不会新增 alipay表不会新增 wechat表不会新增
*/
@Override
@TxTransaction
public void payWithAliPayTimeOut() {
Pay pay = new Pay();
pay.setName("ali|| wechat");
pay.setTotalAmount(BigDecimal.valueOf(200));
pay.setCreateTime(new Date());
payMapper.save(pay);
alipayClient.payTimeOut();
wechatClient.save();
}
/**
* 强一致性测试 执行顺序 pay-->alipay-->wechat
* 当wechat支付失败的时候pay表的数据不会新增 alipay表不会新增 wechat表不会新增
*/
@Override
@TxTransaction
public void payWithWechatPayFail() {
Pay pay = new Pay();
pay.setName("ali|| wechat");
pay.setTotalAmount(BigDecimal.valueOf(200));
pay.setCreateTime(new Date());
payMapper.save(pay);
alipayClient.save();
wechatClient.payFail();
}
/**
* 强一致性测试 执行顺序 pay-->alipay-->wechat
* 当wechat支付超时的时候pay表的数据不会新增 alipay表不会新增 wechat表不会新增
*/
@Override
@TxTransaction
public void payWithWechatPayTimeOut() {
Pay pay = new Pay();
pay.setName("ali|| wechat");
pay.setTotalAmount(BigDecimal.valueOf(200));
pay.setCreateTime(new Date());
payMapper.save(pay);
alipayClient.save();
wechatClient.payTimeOut();
}
}

View File

@ -1,34 +0,0 @@
server:
port: 8881
contextPath: /pay-service
address: 0.0.0.0
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.1.68:3306/pay?useUnicode=true&characterEncoding=utf8
username: xiaoyu
password: Wgj@555888
application:
name: pay-service
mybatis:
type-aliases-package: com.happylifeplat.transaction.tx.springcloud.sample.pay.entiy
#${random.int[9000,9999]}
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
pay-service :
ribbon :
NFLoadBalancerRuleClassName : com.netflix.loadbalancer.RandomRule
MaxAutoRetriesNextServer : 0
logging:
level:
root: info
com.happylifeplat.transaction.core : debug
path: "./logs"

View File

@ -1,93 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
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"
default-autowire="byName">
<context:component-scan base-package="com.happylifeplat.transaction.*"/>
<aop:aspectj-autoproxy expose-proxy="true"/>
<bean id="txTransactionBootstrap" class="com.happylifeplat.transaction.core.bootstrap.TxTransactionBootstrap">
<property name="txManagerUrl" value="http://192.168.1.132:8761"/>
<property name="serializer" value="kryo"/>
<property name="nettySerializer" value="kryo"/>
<property name="blockingQueueType" value="Linked"/>
<property name="compensationCacheType" value="db"/>
<property name="compensation" value="true"/>
<property name="txDbConfig">
<bean class="com.happylifeplat.transaction.common.config.TxDbConfig">
<property name="url"
value="jdbc:mysql://192.168.1.68:3306/tx?useUnicode=true&amp;characterEncoding=utf8"/>
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="username" value="xiaoyu"/>
<property name="password" value="Wgj@555888"/>
</bean>
</property>
</bean>
<!--
<property name="compensationCacheType" value="db"/>
<property name="txDbConfig">
<bean class="com.happylifeplat.transaction.common.config.TxDbConfig">
<property name="url"
value="jdbc:mysql://192.168.1.68:3306/alipay?useUnicode=true&amp;characterEncoding=utf8"/>
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="password" value="Wgj@555888"/>
<property name="username" value="xiaoyu"/>
</bean>
</property>
<property name="compensationCacheType" value="redis"/>
<property name="txRedisConfig">
<bean class="com.happylifeplat.transaction.common.config.TxRedisConfig">
<property name="hostName"
value="192.168.1.78"/>
<property name="port" value="6379"/>
<property name="password" value=""/>
</bean>
</property>
<property name="compensationCacheType" value="zookeeper"/>
<property name="txZookeeperConfig">
<bean class="com.happylifeplat.transaction.common.config.TxZookeeperConfig">
<property name="host" value="192.168.1.132:2181"/>
<property name="sessionTimeOut" value="100000"/>
<property name="rootPath" value="/tx"/>
</bean>
</property>
<property name="compensationCacheType" value="mongodb"/>
<property name="txMongoConfig">
<bean class="com.happylifeplat.transaction.common.config.TxMongoConfig">
<property name="mongoDbUrl" value="192.168.1.78:27017"/>
<property name="mongoDbName" value="happylife"/>
<property name="mongoUserName" value="xiaoyu"/>
<property name="mongoUserPwd" value="123456"/>
</bean>
</property>
<property name="compensationCacheType" value="file"/>
<property name="txFileConfig">
<bean class="com.happylifeplat.transaction.common.config.TxFileConfig">
<property name="path" value=""/>
<property name="prefix" value="tx"/>
</bean>
</property>
-->
</beans>

View File

@ -1,125 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>happylifeplat-transaction-tx-springcloud-sample</artifactId>
<groupId>com.happylifeplat.transaction</groupId>
<version>1.1.0-RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>happylifeplat-transaction-tx-springcloud-sample-wechat</artifactId>
<dependencies>
<dependency>
<groupId>com.happylifeplat.transaction</groupId>
<artifactId>happylifeplat-transaction-tx-springcloud</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<!--spring boot的核心启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--aop支持-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!--自动配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.29</version>
</dependency>
<!--
&lt;!&ndash; mybatis核心包 &ndash;&gt;
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.6</version>
</dependency>
&lt;!&ndash; mybatis/spring包 &ndash;&gt;
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,45 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.wechat;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.ImportResource;
/**
* @author xiaoyu
*/
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
@EnableEurekaClient
@EnableFeignClients
@MapperScan("com.happylifeplat.transaction.tx.springcloud.sample.wechat.mapper")
@ImportResource({"classpath:applicationContext.xml"})
public class WechatApplication {
public static void main(String[] args) {
SpringApplication.run(WechatApplication.class, args);
}
}

View File

@ -1,70 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.wechat.controller;
import com.happylifeplat.transaction.tx.springcloud.sample.wechat.entity.Wechat;
import com.happylifeplat.transaction.tx.springcloud.sample.wechat.service.WechatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author xiaoyu
*/
@RestController
@RequestMapping("/wechat")
public class WechatController {
private final WechatService wechatService;
@Autowired
public WechatController(WechatService wechatService) {
this.wechatService = wechatService;
}
@RequestMapping("/save")
public int save() {
Wechat wechat = new Wechat();
wechat.setAmount(BigDecimal.valueOf(100));
wechat.setName("wechat");
wechat.setCreateTime(new Date());
return wechatService.payment(wechat);
}
@RequestMapping("/payFail")
public void payFail() {
wechatService.payFail();
}
@RequestMapping("/payTimeOut")
public void payTimeOut() {
Wechat wechat = new Wechat();
wechat.setAmount(BigDecimal.valueOf(100));
wechat.setName("wechat");
wechat.setCreateTime(new Date());
wechatService.payTimeOut(wechat);
}
}

View File

@ -1,71 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.wechat.entity;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author xiaoyu
*/
public class Wechat {
private Integer id;
private String name;
/**
* 金额
*/
private BigDecimal amount;
private Date createTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}

View File

@ -1,39 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.wechat.mapper;
import com.happylifeplat.transaction.tx.springcloud.sample.wechat.entity.Wechat;
import org.apache.ibatis.annotations.Insert;
/**
* @author xiaoyu
*/
public interface WechatMapper {
/**
* 保存
*
* @param wechat 实体对象
* @return rows
*/
@Insert("INSERT INTO wechat(name,amount,create_time) VALUES(#{name}, #{amount},#{createTime})")
int save(Wechat wechat);
}

View File

@ -1,46 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.wechat.service;
import com.happylifeplat.transaction.tx.springcloud.sample.wechat.entity.Wechat;
/**
* @author xiaoyu
*/
public interface WechatService {
/**
* 微信付款
*
* @param wechat 实体对象
* @return rows
*/
int payment(Wechat wechat);
/**
* 支付失败
*/
void payFail();
/**
* 支付超时
*
* @param wechat 实体对象
*/
void payTimeOut(Wechat wechat);
}

View File

@ -1,65 +0,0 @@
/*
*
* Copyright 2017-2018 549477611@qq.com(xiaoyu)
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, see <http://www.gnu.org/licenses/>.
*
*/
package com.happylifeplat.transaction.tx.springcloud.sample.wechat.service.impl;
import com.happylifeplat.transaction.core.annotation.TxTransaction;
import com.happylifeplat.transaction.tx.springcloud.sample.wechat.entity.Wechat;
import com.happylifeplat.transaction.tx.springcloud.sample.wechat.mapper.WechatMapper;
import com.happylifeplat.transaction.tx.springcloud.sample.wechat.service.WechatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author xiaoyu
*/
@Service
public class WechatServiceImpl implements WechatService {
private final WechatMapper wechatMapper;
@Autowired
public WechatServiceImpl(WechatMapper wechatMapper) {
this.wechatMapper = wechatMapper;
}
@Override
@TxTransaction
public int payment(Wechat wechat) {
return wechatMapper.save(wechat);
}
@Override
@TxTransaction
public void payFail() {
wechatMapper.save(null);
}
@Override
@TxTransaction
public void payTimeOut(Wechat wechat) {
wechatMapper.save(wechat);
try {
//模拟网络超时
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

View File

@ -1,32 +0,0 @@
server:
port: 8883
contextPath: /wechat-service
address: 0.0.0.0
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.1.68:3306/wechat?useUnicode=true&characterEncoding=utf8
username: xiaoyu
password: Wgj@555888
application:
name: wechat-service
mybatis:
type-aliases-package: com.happylifeplat.transaction.tx.springcloud.sample.wechat.entiy
#${random.int[9000,9999]}
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
wechat-service :
ribbon.NFLoadBalancerRuleClassName : com.netflix.loadbalancer.RandomRule
logging:
level:
root: info
com.happylifeplat.transaction.core : debug
path: "./logs"

View File

@ -1,91 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
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"
default-autowire="byName">
<context:component-scan base-package="com.happylifeplat.transaction.*"/>
<aop:aspectj-autoproxy expose-proxy="true"/>
<bean id="txTransactionBootstrap" class="com.happylifeplat.transaction.core.bootstrap.TxTransactionBootstrap">
<property name="txManagerUrl" value="http://192.168.1.132:8761"/>
<property name="serializer" value="kryo"/>
<property name="nettySerializer" value="kryo"/>
<property name="blockingQueueType" value="Linked"/>
<property name="compensationCacheType" value="db"/>
<property name="compensation" value="true"/>
<property name="txDbConfig">
<bean class="com.happylifeplat.transaction.common.config.TxDbConfig">
<property name="url"
value="jdbc:mysql://192.168.1.68:3306/tx?useUnicode=true&amp;characterEncoding=utf8"/>
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="username" value="xiaoyu"/>
<property name="password" value="Wgj@555888"/>
</bean>
</property>
</bean>
<!--
<property name="compensationCacheType" value="db"/>
<property name="txDbConfig">
<bean class="com.happylifeplat.transaction.common.config.TxDbConfig">
<property name="url"
value="jdbc:mysql://192.168.1.68:3306/alipay?useUnicode=true&amp;characterEncoding=utf8"/>
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="password" value="Wgj@555888"/>
<property name="username" value="xiaoyu"/>
</bean>
</property>
<property name="compensationCacheType" value="redis"/>
<property name="txRedisConfig">
<bean class="com.happylifeplat.transaction.common.config.TxRedisConfig">
<property name="hostName"
value="192.168.1.78"/>
<property name="port" value="6379"/>
<property name="password" value=""/>
</bean>
</property>
<property name="compensationCacheType" value="zookeeper"/>
<property name="txZookeeperConfig">
<bean class="com.happylifeplat.transaction.common.config.TxZookeeperConfig">
<property name="host" value="192.168.1.132:2181"/>
<property name="sessionTimeOut" value="100000"/>
<property name="rootPath" value="/tx"/>
</bean>
</property>
<property name="compensationCacheType" value="mongodb"/>
<property name="txMongoConfig">
<bean class="com.happylifeplat.transaction.common.config.TxMongoConfig">
<property name="mongoDbUrl" value="192.168.1.78:27017"/>
<property name="mongoDbName" value="happylife"/>
<property name="mongoUserName" value="xiaoyu"/>
<property name="mongoUserPwd" value="123456"/>
</bean>
</property>
<property name="compensationCacheType" value="file"/>
<property name="txFileConfig">
<bean class="com.happylifeplat.transaction.common.config.TxFileConfig">
<property name="path" value=""/>
<property name="prefix" value="tx"/>
</bean>
</property>
-->
</beans>