Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# LCN分布式事务框架v4.0

"LCN并不生产事务,LCN只是本地事务的搬运工"
"LCN并不生产事务,LCN只是本地事务的协调者"

## 框架介绍

LCN分布式事务框架是一款事务协调性的框架,框架本身并不创建事务,只是对本地事务做协调控制。因此该框架与其他第三方的框架兼容性强,支持所有的关系型数据库事务,支持多数据源,支持与第三方数据库框架一块使用(例如 sharding-jdbc),在使用框架的时候只需要添加分布式事务的注解即可,对业务的侵入性低。LCN框架主要是为微服务框架提供分布式事务的支持,在微服务框架上做了进一步的事务机制优化,在一些负载场景上LCN事务机制要比本地事务机制的性能更好,4.0以后框架开方了插件机制可以让更多的第三方框架支持进来。
LCN分布式事务框架的核心功能是对本地事务的协调控制,框架本身并不创建事务,只是对本地事务做协调控制。因此该框架与其他第三方的框架兼容性强,支持所有的关系型数据库事务,支持多数据源,支持与第三方数据库框架一块使用(例如 sharding-jdbc),在使用框架的时候只需要添加分布式事务的注解即可,对业务的侵入性低。LCN框架主要是为微服务框架提供分布式事务的支持,在微服务框架上做了进一步的事务机制优化,在一些负载场景上LCN事务机制要比本地事务机制的性能更好,4.0以后框架开方了插件机制可以让更多的第三方框架支持进来。


## 官方网址
Expand Down Expand Up @@ -81,13 +81,13 @@ tx-plugins-db 是LCN 对关系型数据库的插件支持

如上代码执行完成以后两个模块都将回滚事务。

说明:在使用LCN分布式事务时,只需要将事务的开始方法添加`@TxTransaction(isStart=true)`注解即可,在参与方添加`@TxTransaction`即可。详细见demo教程
说明:在使用LCN分布式事务时,只需要将事务的开始方法添加`@TxTransaction(isStart=true)`注解即可,在参与方添加`@TxTransaction`或者实现`ITxTransaction`接口即可。详细见demo教程

## 关于@TxTransaction 使用说明

@TxTransaction注解是分布式事务的标示。

若存在业务方法:a->b b->c b->d,那么开启分布式事务注解的话,只需要在a方法上添加@TxTransaction即可。
若存在业务方法:a->b b->c b->d,那么开启分布式事务注解的话,需要在各个模块方法上添加@TxTransaction即可。

```
@TxTransaction(isStart=true)
Expand All @@ -112,10 +112,7 @@ tx-plugins-db 是LCN 对关系型数据库的插件支持
## maven 中心库地址



```


<dependency>
<groupId>com.codingapi</groupId>
<artifactId>tx-client</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.codingapi</groupId>
<artifactId>tx-lcn</artifactId>
<version>4.0.3</version>
<version>4.1.0</version>
<packaging>pom</packaging>

<name>tx-lcn</name>
Expand All @@ -32,7 +32,7 @@
<java.version>1.7</java.version>
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>

<lcn.last.version>4.0.3</lcn.last.version>
<lcn.last.version>4.1.0</lcn.last.version>
</properties>


Expand Down
2 changes: 1 addition & 1 deletion transaction-dubbo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.codingapi</groupId>
<artifactId>tx-lcn</artifactId>
<version>4.0.3</version>
<version>4.1.0</version>
</parent>

<groupId>com.codingapi</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,24 @@ public class ModelNameServiceImpl implements ModelNameService {
@Autowired
private ApplicationConfig applicationConfig;

@Autowired
private ProviderConfig providerConfig;

@Autowired
private ApplicationContext applicationContext;

public RegistryConfig getRegistryConfig(){
private ProviderConfig providerConfig(){
Map<String, ProviderConfig> beans = applicationContext.getBeansOfType(ProviderConfig.class);
ProviderConfig providerConfig = null;
if(beans!=null){
String defaultKey = "default";
for(String key:beans.keySet()){
defaultKey = key;
}

providerConfig = beans.get(defaultKey);
}
return providerConfig;
}

private RegistryConfig getRegistryConfig(){
Map<String, RegistryConfig> beans = applicationContext.getBeansOfType(RegistryConfig.class);
RegistryConfig registryConfig = null;
if(beans!=null){
Expand Down Expand Up @@ -64,7 +75,7 @@ private String getIp() {

@Override
public String getUniqueKey() {
String address = getIp() + providerConfig.getPort();
String address = getIp() + getPort();
return MD5Util.md5(address.getBytes());
}

Expand All @@ -75,8 +86,8 @@ public String getIpAddress() {
}

private int getPort(){
if(providerConfig.getPort()!=null){
return providerConfig.getPort();
if(providerConfig()!=null&&providerConfig().getPort()!=null){
return providerConfig().getPort();
}

RegistryConfig registryConfig = getRegistryConfig();
Expand Down
2 changes: 1 addition & 1 deletion transaction-motan/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.codingapi</groupId>
<artifactId>tx-lcn</artifactId>
<version>4.0.3</version>
<version>4.1.0</version>
</parent>

<groupId>com.codingapi</groupId>
Expand Down
2 changes: 1 addition & 1 deletion transaction-springcloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi</groupId>
<artifactId>tx-lcn</artifactId>
<version>4.0.3</version>
<version>4.1.0</version>
</parent>

<groupId>com.codingapi</groupId>
Expand Down
2 changes: 1 addition & 1 deletion tx-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi</groupId>
<artifactId>tx-lcn</artifactId>
<version>4.0.3</version>
<version>4.1.0</version>
</parent>

<groupId>com.codingapi</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void welcome(){
System.out.println("\t\t** \t\t** \t\t** ***");
System.out.println("\t\t*****\t\t ****\t\t** **");
System.out.println();
System.out.println("\t\tLCN-Client version:4.0.3");
System.out.println("\t\tLCN-Client version:4.1.0");
System.out.println();
}

Expand Down
8 changes: 7 additions & 1 deletion tx-manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.codingapi</groupId>
<artifactId>tx-manager</artifactId>
<version>4.0.3</version>
<version>4.1.0</version>
<packaging>jar</packaging>

<name>tx-manager</name>
Expand Down Expand Up @@ -61,6 +61,12 @@
</exclusions>
</dependency>


<!--<dependency>-->
<!--<groupId>org.springframework.cloud</groupId>-->
<!--<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>-->
<!--</dependency>-->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void welcome(){
System.out.println("\t\t** \t\t** \t\t** ***");
System.out.println("\t\t*****\t\t ****\t\t** **");
System.out.println();
System.out.println("\t\tLCN-TxManager version:4.0.3");
System.out.println("\t\tLCN-TxManager version:4.1.0");
System.out.println();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
import com.codingapi.tm.manager.service.MicroService;
import com.codingapi.tm.model.TxServer;
import com.codingapi.tm.model.TxState;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.shared.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
Expand Down Expand Up @@ -39,15 +35,6 @@ public class MicroServiceImpl implements MicroService {
private DiscoveryClient discoveryClient;


@Autowired
private EurekaClient eurekaClient;




/** logger */
private static final Logger logger = LoggerFactory.getLogger(MicroServiceImpl.class);


private boolean isIp(String ipAddress) {
String ip = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";
Expand All @@ -57,19 +44,10 @@ private boolean isIp(String ipAddress) {
}


public List<InstanceInfo> getConfigServiceInstances() {
Application application = eurekaClient.getApplication(tmKey);
if (application == null) {
logger.error("get eureka server error!");
}
return application != null ? application.getInstances() : new ArrayList<InstanceInfo>();
}

@Override
public TxState getState() {
TxState state = new TxState();

//String ipAddress = EurekaServerContextHolder.getInstance().getServerContext().getApplicationInfoManager().getEurekaInstanceConfig().getIpAddress();
String ipAddress = discoveryClient.getLocalServiceInstance().getHost();
if(!isIp(ipAddress)){
ipAddress = "127.0.0.1";
Expand All @@ -89,19 +67,11 @@ public TxState getState() {
return state;
}


private List<String> getServices(){
List<String> urls = new ArrayList<>();
List<InstanceInfo> instanceInfos =getConfigServiceInstances();
for (InstanceInfo instanceInfo : instanceInfos) {
String url = instanceInfo.getHomePageUrl();
String address = instanceInfo.getIPAddr();
if (isIp(address)) {
urls.add(url);
}else{
url = url.replace(address,"127.0.0.1");
urls.add(url);
}
List<ServiceInstance> serviceInstances = discoveryClient.getInstances(tmKey);
for (ServiceInstance instanceInfo : serviceInstances) {
urls.add(instanceInfo.getUri().toASCIIString());
}
return urls;
}
Expand Down
7 changes: 7 additions & 0 deletions tx-manager/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ spring.resources.static-locations=classpath:/static/
#######################################txmanager-end#################################################


#zookeeper地址
#spring.cloud.zookeeper.connect-string=127.0.0.1:2181
#spring.cloud.zookeeper.discovery.preferIpAddress = true

#eureka 地址
eureka.client.service-url.defaultZone=http://127.0.0.1:8761/eureka/
eureka.instance.prefer-ip-address=true

#######################################redis-start#################################################
#redis 配置文件,根据情况选择集群或者单机模式
Expand Down
19 changes: 0 additions & 19 deletions tx-manager/src/main/resources/bootstrap.yml

This file was deleted.

4 changes: 2 additions & 2 deletions tx-manager/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8"/>
<title>TxManager v4.0.3</title>
<title>TxManager v4.1.0</title>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="static/bootstrap/css/bootstrap.min.css"/>
<script src="static/jquery/jquery.min.js"></script>
Expand All @@ -24,7 +24,7 @@
<body>
<div class="container">

<h3 class="text-center">TxManagerV4.0.3 服务已启动</h3>
<h3 class="text-center">TxManagerV4.1.0 服务已启动</h3>
<div class="table-responsive">
<table class="table table-bordered table-striped">
<colgroup>
Expand Down
2 changes: 1 addition & 1 deletion tx-plugins-db/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi</groupId>
<artifactId>tx-lcn</artifactId>
<version>4.0.3</version>
<version>4.1.0</version>
</parent>

<groupId>com.codingapi</groupId>
Expand Down