Skip to content

Commit

Permalink
Merge pull request #80 from QNJR-GROUP/1.x
Browse files Browse the repository at this point in the history
Version 1.1.0
  • Loading branch information
skyesx authored Sep 16, 2018
2 parents 5b82373 + f36b59d commit d14853e
Show file tree
Hide file tree
Showing 33 changed files with 269 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public EasyTransResult doInTransaction(TransactionStatus status) {

IdempotentPo idempotentPo = helper.getIdempotentPo(filterChain, header, request);
ExecuteOrder executeOrder = helper.getExecuteOrder(filterChain.getAppId(), filterChain.getBusCode(), filterChain.getInnerMethodName());
String objectMD5 = ObjectDigestUtil.getObjectMD5(request);

byte[] serialization = serializer.serialization(request);
String objectMD5 = ObjectDigestUtil.MD5Encode(serialization);

EasyTransResult innerResult = filterResult(idempotentPo, objectMD5, executeOrder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import com.yiqiniu.easytrans.protocol.EasyTransRequest;
import com.yiqiniu.easytrans.protocol.tcc.TccMethodRequest;

public class CallWrappUtil {
public class CallWrapUtil {

private EasyTransFacade facade;

public CallWrappUtil(EasyTransFacade facade) {
public CallWrapUtil(EasyTransFacade facade) {
this.facade = facade;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,27 @@ public static String MD5Encode(String origin) {
md.update(resultString.getBytes("UTF-8"));
resultString = byteArrayToHexString(md.digest());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return resultString;
}


/**
* MD5编码
*
* @param origin
* 原始字符串
* @return 经过MD5加密之后的结果
*/
public static String MD5Encode(byte[] origin) {
String resultString = null;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(origin);
resultString = byteArrayToHexString(md.digest());
} catch (Exception e) {
throw new RuntimeException(e);
}
return resultString;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.yiqiniu.easytrans.EnableEasyTransaction;
import com.yiqiniu.easytrans.demos.wallet.api.WalletPayMoneyService;
import com.yiqiniu.easytrans.demos.wallet.api.requestcfg.WalletPayRequestCfg;
import com.yiqiniu.easytrans.util.CallWrappUtil;
import com.yiqiniu.easytrans.util.CallWrapUtil;

@SpringBootApplication
@EnableEasyTransaction
Expand All @@ -22,7 +22,7 @@ public static void main(String[] args) {
* create WalletPayMoneyService instance, you can inject the instance to call wallet tcc service
*/
@Bean
public WalletPayMoneyService payService(CallWrappUtil util) {
public WalletPayMoneyService payService(CallWrapUtil util) {
return util.createTransactionCallInstance(WalletPayMoneyService.class, WalletPayRequestCfg.class);
}

Expand Down
2 changes: 1 addition & 1 deletion easytrans-demo/interface-call/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<revision>1.0.0</revision>
<revision>1.1.0</revision>
</properties>


Expand Down
2 changes: 1 addition & 1 deletion easytrans-demo/rpc-dubbo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<revision>1.0.0</revision>
<revision>1.1.0</revision>
</properties>


Expand Down
1 change: 0 additions & 1 deletion easytrans-demo/rpc-dubbo/rpcdubbo-order-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
<groupId>com.yiqiniu.easytrans</groupId>
<artifactId>easytrans-rpc-dubbo-starter</artifactId>
<exclusions>
<!-- dubbo import a very old version spring , exclude it -->
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.yiqiniu.easytrans.demos.order.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.rpc.service.GenericService;
import com.yiqiniu.easytrans.EnableEasyTransaction;
import com.yiqiniu.easytrans.rpc.impl.dubbo.DubboReferanceCustomizationer;
import com.yiqiniu.easytrans.rpc.impl.dubbo.EnableRpcDubboImpl;

@SpringBootApplication
Expand All @@ -15,4 +21,21 @@ public class OrderApplication {
public static void main(String[] args) {
SpringApplication.run(OrderApplication.class, args);
}


/**
* This is an optional bean, you can modify Dubbo reference here to change the behavior of consumer
* @return
*/
@Bean
public DubboReferanceCustomizationer dubboConsumerCustomizationer() {
return new DubboReferanceCustomizationer() {

@Override
public void customDubboReferance(String appId, String busCode, ReferenceConfig<GenericService> referenceConfig) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.info("custom dubbo consumer!");
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ easytrans:
rpc:
dubbo:
enabled: true
dubbo-zk-url: zookeeper://${easytrans.master.zk.zooKeeperUrl}

stringcodec:
zk:
zooKeeperUrl: ${easytrans.master.zk.zooKeeperUrl}
Expand All @@ -37,6 +37,19 @@ easytrans:
password: 123456



# Dubbo Config properties
# please refer https://dubbo.incubator.apache.org/en-us/docs/user/references/xml/introduction.html
dubbo:
application:
name: order-service
protocol:
name: dubbo
port: 20880
registry:
address: zookeeper://localhost:2281
provider:
timeout: 1000
consumer:
timeout: 1000


1 change: 0 additions & 1 deletion easytrans-demo/rpc-dubbo/rpcdubbo-wallet-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<dependency>
<groupId>com.yiqiniu.easytrans</groupId>
<artifactId>easytrans-core</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>

Expand Down
1 change: 0 additions & 1 deletion easytrans-demo/rpc-dubbo/rpcdubbo-wallet-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<groupId>com.yiqiniu.easytrans</groupId>
<artifactId>easytrans-rpc-dubbo-starter</artifactId>
<exclusions>
<!-- dubbo import a very old version spring , exclude it -->
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.yiqiniu.easytrans.demos.wallet.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.alibaba.dubbo.config.ServiceConfig;
import com.alibaba.dubbo.rpc.service.GenericService;
import com.yiqiniu.easytrans.EnableEasyTransaction;
import com.yiqiniu.easytrans.protocol.BusinessIdentifer;
import com.yiqiniu.easytrans.rpc.impl.dubbo.DubboServiceCustomizationer;
import com.yiqiniu.easytrans.rpc.impl.dubbo.EnableRpcDubboImpl;

@SpringBootApplication
Expand All @@ -28,6 +35,24 @@ public void run() {
}
}
}
}.start();;
}.start();
}


/**
* This is an optional bean, you can modify Dubbo reference here to change the behavior of consumer
*/
@Bean
public DubboServiceCustomizationer dubboProviderCustomizationer() {
return new DubboServiceCustomizationer() {

@Override
public void customDubboService(BusinessIdentifer businessIdentifer,
ServiceConfig<GenericService> serviceConfig) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.info("custom dubbo provider!");

}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.yiqiniu.easytrans.core.EasyTransFacade;
import com.yiqiniu.easytrans.demos.wallet.api.vo.WalletPayVO.WalletPayRequestVO;
Expand All @@ -17,7 +18,7 @@ public class WalletService {
@Resource
private JdbcTemplate jdbcTemplate;


@Transactional
public WalletPayResponseVO doTryPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount + ? where user_id = ? and (total_amount - freeze_amount) >= ?;",
param.getPayAmount(),param.getUserId(),param.getPayAmount());
Expand All @@ -31,7 +32,7 @@ public WalletPayResponseVO doTryPay(WalletPayRequestVO param) {
return walletPayTccMethodResult;
}


@Transactional
public void doConfirmPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount - ?, total_amount = total_amount - ? where user_id = ?;",
param.getPayAmount(),param.getPayAmount(),param.getUserId());
Expand All @@ -41,6 +42,7 @@ public void doConfirmPay(WalletPayRequestVO param) {
}
}

@Transactional
public void doCancelPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount - ? where user_id = ?;",
param.getPayAmount(),param.getUserId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ easytrans:
rpc:
dubbo:
enabled: true
dubbo-zk-url: zookeeper://${easytrans.master.zk.zooKeeperUrl}
stringcodec:
zk:
zooKeeperUrl: ${easytrans.master.zk.zooKeeperUrl}
Expand All @@ -39,6 +38,16 @@ easytrans:



# Dubbo Config properties
# please refer https://dubbo.incubator.apache.org/en-us/docs/user/references/xml/introduction.html
dubbo:
application:
name: order-service
protocol:
name: dubbo
port: 20881
registry:
address: zookeeper://localhost:2281



2 changes: 1 addition & 1 deletion easytrans-demo/sagatcc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<revision>1.0.0</revision>
<revision>1.1.0</revision>
</properties>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.yiqiniu.easytrans.core.EasyTransFacade;
import com.yiqiniu.easytrans.demos.wallet.api.vo.WalletPayVO.WalletPayRequestVO;
Expand All @@ -16,7 +17,7 @@ public class WalletService {
@Resource
private JdbcTemplate jdbcTemplate;


@Transactional
public void doTryPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount + ? where user_id = ? and (total_amount - freeze_amount) >= ?;",
param.getPayAmount(),param.getUserId(),param.getPayAmount());
Expand All @@ -26,7 +27,7 @@ public void doTryPay(WalletPayRequestVO param) {
}
}


@Transactional
public void doConfirmPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount - ?, total_amount = total_amount - ? where user_id = ?;",
param.getPayAmount(),param.getPayAmount(),param.getUserId());
Expand All @@ -36,6 +37,7 @@ public void doConfirmPay(WalletPayRequestVO param) {
}
}

@Transactional
public void doCancelPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount - ? where user_id = ?;",
param.getPayAmount(),param.getUserId());
Expand Down
2 changes: 1 addition & 1 deletion easytrans-demo/tcc-and-msg/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<revision>1.0.0</revision>
<revision>1.1.0</revision>
</properties>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.yiqiniu.easytrans.core.EasyTransFacade;
import com.yiqiniu.easytrans.demos.wallet.api.vo.WalletPayVO.WalletPayRequestVO;
Expand All @@ -17,7 +18,7 @@ public class WalletService {
@Resource
private JdbcTemplate jdbcTemplate;


@Transactional
public WalletPayResponseVO doTryPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount + ? where user_id = ? and (total_amount - freeze_amount) >= ?;",
param.getPayAmount(),param.getUserId(),param.getPayAmount());
Expand All @@ -31,7 +32,7 @@ public WalletPayResponseVO doTryPay(WalletPayRequestVO param) {
return walletPayTccMethodResult;
}


@Transactional
public void doConfirmPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount - ?, total_amount = total_amount - ? where user_id = ?;",
param.getPayAmount(),param.getPayAmount(),param.getUserId());
Expand All @@ -41,6 +42,7 @@ public void doConfirmPay(WalletPayRequestVO param) {
}
}

@Transactional
public void doCancelPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount - ? where user_id = ?;",
param.getPayAmount(),param.getUserId());
Expand Down
2 changes: 1 addition & 1 deletion easytrans-demo/tcc-only/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<revision>1.0.0</revision>
<revision>1.1.0</revision>
</properties>


Expand Down
1 change: 0 additions & 1 deletion easytrans-demo/tcc-only/tcconly-wallet-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<dependency>
<groupId>com.yiqiniu.easytrans</groupId>
<artifactId>easytrans-core</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>

Expand Down
Loading

0 comments on commit d14853e

Please sign in to comment.