提交 bd2b6021 编写于 作者: U ujued

tx: remove sleuth.

上级 0e66460e
......@@ -18,12 +18,8 @@
<modules>
<module>tx-client</module>
<module>tx-commons</module>
<module>tx-jdbcproxy-p6spy</module>
<module>tx-spi-message</module>
<module>tx-spi-message-netty</module>
<module>tx-spi-sleuth</module>
<module>tx-client-springcloud</module>
<module>tx-client-dubbo</module>
<module>tx-manager</module>
<module>tx-logger</module>
<module>tx-test</module>
......
<?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>tx-lcn</artifactId>
<groupId>com.codingapi.txlcn</groupId>
<version>5.0.0.RC2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>tx-client-dubbo</artifactId>
<dependencies>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.brave</groupId>
<artifactId>brave-instrumentation-dubbo-rpc</artifactId>
</dependency>
<dependency>
<groupId>com.codingapi.txlcn</groupId>
<artifactId>tx-client</artifactId>
</dependency>
<dependency>
<groupId>com.codingapi.txlcn</groupId>
<artifactId>tx-spi-sleuth</artifactId>
</dependency>
<dependency>
<groupId>com.codingapi.txlcn</groupId>
<artifactId>tx-spi-message-netty</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.tc.spi;
import com.codingapi.txlcn.tc.spi.sleuth.dubbo.TxLcnDubboInitializer;
import com.codingapi.txlcn.spi.sleuth.listener.SleuthParamListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* Description:
* Company: CodingApi
* Date: 2018/12/14
*
* @author ujued
*/
@Configuration
@ComponentScan
public class SleuthConfiguration {
static {
System.setProperty("dubbo.provider.filter","tracing");
System.setProperty("dubbo.consumer.filter","tracing");
}
@Bean
public TxLcnDubboInitializer txLcnDubboInitializer(SleuthParamListener sleuthParamListener) {
return new TxLcnDubboInitializer(sleuthParamListener);
}
}
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.tc.spi.sleuth.dubbo;
import com.codingapi.txlcn.tc.spi.sleuth.dubbo.loadbalance.TXLCNLoadBalance;
import com.codingapi.txlcn.commons.runner.TxLcnInitializer;
import com.codingapi.txlcn.spi.sleuth.listener.SleuthParamListener;
import lombok.extern.slf4j.Slf4j;
/**
* Description:
* Company: CodingApi
* Date: 2018/12/14
*
* @author ujued
*/
@Slf4j
public class TxLcnDubboInitializer implements TxLcnInitializer {
private SleuthParamListener sleuthParamListener;
public TxLcnDubboInitializer(SleuthParamListener sleuthParamListener){
this.sleuthParamListener=sleuthParamListener;
}
@Override
public void init() throws Exception{
TXLCNLoadBalance.sleuthParamListener = sleuthParamListener;
log.info("init sleuthParamListener->{}",sleuthParamListener);
}
}
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.tc.spi.sleuth.dubbo.loadbalance;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.cluster.loadbalance.ConsistentHashLoadBalance;
import java.util.List;
/**
* Description:
* Company: CodingApi
* Date: 2018/12/14
*
* @author ujued
*/
public class TXLCNConsistentHashLoadBalance extends ConsistentHashLoadBalance {
@Override
public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invocation) {
return TXLCNLoadBalance.chooseInvoker(invokers, url, invocation, this::loadSelect);
}
public <T> Invoker<T> loadSelect(List<Invoker<T>> invokers, URL url, Invocation invocation){
return super.select(invokers, url, invocation);
}
}
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.tc.spi.sleuth.dubbo.loadbalance;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance;
import java.util.List;
/**
* Description:
* Company: CodingApi
* Date: 2018/12/14
*
* @author ujued
*/
public class TXLCNLeastActiveLoadBalance extends LeastActiveLoadBalance {
@Override
public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invocation) {
return TXLCNLoadBalance.chooseInvoker(invokers, url, invocation, this::loadSelect);
}
public <T> Invoker<T> loadSelect(List<Invoker<T>> invokers, URL url, Invocation invocation){
return super.select(invokers, url, invocation);
}
}
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.tc.spi.sleuth.dubbo.loadbalance;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.RpcContext;
import com.codingapi.txlcn.spi.sleuth.listener.SleuthParamListener;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
/**
* Description:
* Company: CodingApi
* Date: 2018/12/14
*
* @author ujued
*/
@Slf4j
public class TXLCNLoadBalance {
public static SleuthParamListener sleuthParamListener;
static <T> Invoker<T> chooseInvoker(List<Invoker<T>> invokers, URL url, Invocation invocation, TxLcnLoadBalance loadBalance) {
String localKey = RpcContext.getContext().getLocalAddressString();
List<String> appList = sleuthParamListener.beforeBalance(localKey);
Invoker<T> chooseInvoker = null;
for (Invoker<T> tInvoker : invokers) {
String serverKey = tInvoker.getUrl().getAddress();
for (String appKey : appList) {
if (appKey.equals(serverKey)) {
chooseInvoker = tInvoker;
}
}
}
if (chooseInvoker == null) {
Invoker<T> invoker = loadBalance.select(invokers, url, invocation);
sleuthParamListener.afterNewBalance(invoker.getUrl().getAddress());
return invoker;
} else {
return chooseInvoker;
}
}
@FunctionalInterface
public interface TxLcnLoadBalance {
<T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invocation);
}
}
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.tc.spi.sleuth.dubbo.loadbalance;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.cluster.loadbalance.RandomLoadBalance;
import java.util.List;
/**
* Description:
* Company: CodingApi
* Date: 2018/12/14
*
* @author ujued
*/
public class TXLCNRandomLoadBalance extends RandomLoadBalance {
@Override
public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invocation) {
return TXLCNLoadBalance.chooseInvoker(invokers, url, invocation, this::loadSelect);
}
public <T> Invoker<T> loadSelect(List<Invoker<T>> invokers, URL url, Invocation invocation){
return super.select(invokers, url, invocation);
}
}
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.tc.spi.sleuth.dubbo.loadbalance;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance;
import java.util.List;
/**
* Description:
* Company: CodingApi
* Date: 2018/12/14
*
* @author ujued
*/
public class TXLCNRoundRobinLoadBalance extends RoundRobinLoadBalance {
@Override
public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invocation) {
return TXLCNLoadBalance.chooseInvoker(invokers, url, invocation, this::loadSelect);
}
public <T> Invoker<T> loadSelect(List<Invoker<T>> invokers, URL url, Invocation invocation){
return super.select(invokers, url, invocation);
}
}
txlcn_random=com.codingapi.txlcn.tc.spi.sleuth.dubbo.loadbalance.TXLCNRandomLoadBalance
txlcn_roundrobin=com.codingapi.txlcn.tc.spi.sleuth.dubbo.loadbalance.TXLCNRoundRobinLoadBalance
txlcn_leastactive=com.codingapi.txlcn.tc.spi.sleuth.dubbo.loadbalance.TXLCNLeastActiveLoadBalance
txlcn_consistenthash=com.codingapi.txlcn.tc.spi.sleuth.dubbo.loadbalance.TXLCNConsistentHashLoadBalance
\ No newline at end of file
<?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>tx-lcn</artifactId>
<groupId>com.codingapi.txlcn</groupId>
<version>5.0.0.RC2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>tx-client-springcloud</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
<groupId>com.codingapi.txlcn</groupId>
<artifactId>tx-client</artifactId>
</dependency>
<dependency>
<groupId>com.codingapi.txlcn</groupId>
<artifactId>tx-spi-message-netty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>com.codingapi.txlcn</groupId>
<artifactId>tx-spi-sleuth</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.tc.spi;
import com.codingapi.txlcn.spi.sleuth.listener.SleuthParamListener;
import com.codingapi.txlcn.tc.spi.sleuth.springcloud.ribbon.loadbalance.TXLCNZoneAvoidanceRule;
import com.netflix.loadbalancer.IRule;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
/**
* Description:
* Company: CodingApi
* Date: 2018/12/13
*
* @author ujued
*/
@Data
@ComponentScan
@Configuration
@ConfigurationProperties(prefix = "tx-lcn.springcloud.loadbalance")
public class SleuthConfiguration {
private boolean enabled = false;
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "tx-lcn.springcloud.loadbalance.enabled",havingValue = "true")
@Scope("prototype")
public IRule ribbonRule(SleuthParamListener sleuthParamListener,
Registration registration){
return new TXLCNZoneAvoidanceRule(sleuthParamListener, registration);
}
@Bean
public StringBuilder stringBuilder(){
return new StringBuilder();
}
}
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.tc.spi.sleuth.springcloud.ribbon.customizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor;
import org.springframework.cloud.client.loadbalancer.RestTemplateCustomizer;
import org.springframework.cloud.client.loadbalancer.RetryLoadBalancerInterceptor;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
/**
* Description: set loadBalancerInterceptor to first.
* Company: CodingApi
* Date: 2018/12/18
*
* @author codingapi
*/
@Component
public class RibbonFirstRestTemplateCustomizer implements RestTemplateCustomizer {
@Autowired(required = false)
private LoadBalancerInterceptor loadBalancerInterceptor;
@Autowired(required = false)
private RetryLoadBalancerInterceptor retryLoadBalancerInterceptor;
@Override
public void customize(RestTemplate restTemplate) {
List<ClientHttpRequestInterceptor> list = new ArrayList<>(restTemplate.getInterceptors());
if(loadBalancerInterceptor!=null) {
list.add(0, loadBalancerInterceptor);
}
if(retryLoadBalancerInterceptor!=null){
list.add(0, retryLoadBalancerInterceptor);
}
restTemplate.setInterceptors(list);
}
}
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.tc.spi.sleuth.springcloud.ribbon.loadbalance;
import com.codingapi.txlcn.spi.sleuth.listener.SleuthParamListener;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ZoneAvoidanceRule;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.serviceregistry.Registration;
import java.util.List;
/**
* Description:
* Company: CodingApi
* Date: 2018/12/13
*
* @author ujued
*/
@Slf4j
public class TXLCNZoneAvoidanceRule extends ZoneAvoidanceRule {
//针对sleuth 负载控制的ExtraField参数设置
private final SleuthParamListener sleuthParamListener;
private final Registration registration;
/**
* 无参构造器提供给Ribbon调用
*/
public TXLCNZoneAvoidanceRule() {
this.sleuthParamListener = null;
this.registration = null;
}
public TXLCNZoneAvoidanceRule(SleuthParamListener sleuthParamListener,
Registration registration) {
this.sleuthParamListener = sleuthParamListener;
this.registration = registration;
}
@Override
public Server choose(Object key) {
return getServer(key);
}
private Server getServer(Object key) {
String localKey = String.format("%s:%s:%s", registration.getServiceId(), registration.getHost(), registration.getPort());
List<String> appList = sleuthParamListener.beforeBalance(localKey);
Server balanceServer = null;
List<Server> servers = getLoadBalancer().getAllServers();
log.debug("load balanced rule servers: {}", servers);
for (Server server : servers) {
for (String appKey : appList) {
String serverKey = String.format("%s:%s", server.getMetaInfo().getAppName(), server.getHostPort());
if (serverKey.equals(appKey)) {
balanceServer = server;
}
}
}
if (balanceServer == null) {
Server server = super.choose(key);
sleuthParamListener.afterNewBalance(String.format("%s:%s", server.getMetaInfo().getAppName(), server.getHostPort()));
return server;
} else {
return balanceServer;
}
}
}
......@@ -26,20 +26,9 @@
<artifactId>tx-logger</artifactId>
</dependency>
<dependency>
<groupId>com.codingapi.txlcn</groupId>
<artifactId>tx-spi-message</artifactId>
</dependency>
<dependency>
<groupId>com.codingapi.txlcn</groupId>
<artifactId>tx-jdbcproxy-p6spy</artifactId>
</dependency>
<dependency>
<groupId>com.codingapi.txlcn</groupId>
<artifactId>tx-tracing</artifactId>
<version>5.0.0.RC2</version>
</dependency>
<dependency>
......@@ -57,6 +46,10 @@
<artifactId>spring-tx</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.codingapi.txlcn</groupId>
<artifactId>tx-spi-message</artifactId>
</dependency>
</dependencies>
......
......@@ -22,7 +22,7 @@ import com.codingapi.txlcn.tc.core.txc.analy.def.TxcService;
import com.codingapi.txlcn.tc.core.txc.analy.def.bean.*;
import com.codingapi.txlcn.tc.core.txc.analy.util.SqlUtils;
import com.codingapi.txlcn.commons.exception.TxcLogicException;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.StatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.common.StatementInformation;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
......
......@@ -16,7 +16,7 @@
package com.codingapi.txlcn.tc.core.txc.analy.def;
import com.codingapi.txlcn.tc.core.txc.analy.def.bean.LockableSelect;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.StatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.common.StatementInformation;
import net.sf.jsqlparser.statement.delete.Delete;
import net.sf.jsqlparser.statement.insert.Insert;
import net.sf.jsqlparser.statement.update.Update;
......
......@@ -18,10 +18,10 @@
package com.codingapi.txlcn.tc.core.txc.resource;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.*;
import com.codingapi.txlcn.jdbcproxy.p6spy.event.DefaultEventListener;
import com.codingapi.txlcn.jdbcproxy.p6spy.event.JdbcEventListener;
import com.codingapi.txlcn.jdbcproxy.p6spy.event.P6spyJdbcEventListener;
import com.codingapi.txlcn.tc.support.p6spy.common.*;
import com.codingapi.txlcn.tc.support.p6spy.event.DefaultEventListener;
import com.codingapi.txlcn.tc.support.p6spy.event.JdbcEventListener;
import com.codingapi.txlcn.tc.support.p6spy.event.P6spyJdbcEventListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......
......@@ -15,8 +15,8 @@
*/
package com.codingapi.txlcn.tc.core.txc.resource;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.ConnectionInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.wrapper.ConnectionWrapper;
import com.codingapi.txlcn.tc.support.p6spy.common.ConnectionInformation;
import com.codingapi.txlcn.tc.support.p6spy.wrapper.ConnectionWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......
......@@ -18,9 +18,9 @@ package com.codingapi.txlcn.tc.core.txc.resource;
import com.codingapi.txlcn.tc.core.DTXLocalContext;
import com.codingapi.txlcn.tc.core.txc.analy.def.SqlExecuteInterceptor;
import com.codingapi.txlcn.tc.core.txc.analy.def.bean.LockableSelect;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.PreparedStatementInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.StatementInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.event.P6spyJdbcEventListener;
import com.codingapi.txlcn.tc.support.p6spy.common.PreparedStatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.common.StatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.event.P6spyJdbcEventListener;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.common;
package com.codingapi.txlcn.tc.support.p6spy.common;
import java.util.HashMap;
import java.util.Map;
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.common;
package com.codingapi.txlcn.tc.support.p6spy.common;
/**
* {@link Hasher} using {@code class.hashCode()} for object hash computing.
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.common;
package com.codingapi.txlcn.tc.support.p6spy.common;
import java.sql.Connection;
import java.util.concurrent.atomic.AtomicInteger;
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.common;
package com.codingapi.txlcn.tc.support.p6spy.common;
import java.util.*;
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.common;
package com.codingapi.txlcn.tc.support.p6spy.common;
/**
* Alternative hash code implementation for the usage with {@link CustomHashedHashSet}.
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.common;
package com.codingapi.txlcn.tc.support.p6spy.common;
/**
* Assures capability of the class to be logged by
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.common;
package com.codingapi.txlcn.tc.support.p6spy.common;
import java.io.File;
import java.net.URL;
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.common;
package com.codingapi.txlcn.tc.support.p6spy.common;
import java.util.HashMap;
import java.util.Map;
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.common;
package com.codingapi.txlcn.tc.support.p6spy.common;
//import com.p6spy.engine.logging.Category;
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.common;
package com.codingapi.txlcn.tc.support.p6spy.common;
import java.sql.Statement;
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.common;
package com.codingapi.txlcn.tc.support.p6spy.common;
......
......@@ -15,14 +15,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.event;
package com.codingapi.txlcn.tc.support.p6spy.event;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.CallableStatementInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.PreparedStatementInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.ResultSetInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.StatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.common.CallableStatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.common.PreparedStatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.common.ResultSetInformation;
import com.codingapi.txlcn.tc.support.p6spy.common.StatementInformation;
import java.sql.SQLException;
......
......@@ -15,10 +15,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.event;
package com.codingapi.txlcn.tc.support.p6spy.event;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.*;
import com.codingapi.txlcn.tc.support.p6spy.common.*;
import javax.sql.DataSource;
import java.sql.*;
......
......@@ -15,13 +15,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.event;
package com.codingapi.txlcn.tc.support.p6spy.event;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.PreparedStatementInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.StatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.common.PreparedStatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.common.StatementInformation;
import java.sql.SQLException;
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.wrapper;
package com.codingapi.txlcn.tc.support.p6spy.wrapper;
import java.sql.SQLException;
import java.sql.Wrapper;
......
......@@ -15,10 +15,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.wrapper;
package com.codingapi.txlcn.tc.support.p6spy.wrapper;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.CallableStatementInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.event.JdbcEventListener;
import com.codingapi.txlcn.tc.support.p6spy.common.CallableStatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.event.JdbcEventListener;
import java.io.InputStream;
import java.io.Reader;
......
......@@ -15,14 +15,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.wrapper;
package com.codingapi.txlcn.tc.support.p6spy.wrapper;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.CallableStatementInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.ConnectionInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.PreparedStatementInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.StatementInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.event.JdbcEventListener;
import com.codingapi.txlcn.tc.support.p6spy.common.CallableStatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.common.ConnectionInformation;
import com.codingapi.txlcn.tc.support.p6spy.common.PreparedStatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.common.StatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.event.JdbcEventListener;
import lombok.extern.slf4j.Slf4j;
import java.sql.*;
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.wrapper;
package com.codingapi.txlcn.tc.support.p6spy.wrapper;
/**
* Marker interface added to all proxies generated by P6Spy. Any object which implements this interface
......
......@@ -15,12 +15,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.wrapper;
package com.codingapi.txlcn.tc.support.p6spy.wrapper;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.PreparedStatementInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.ResultSetInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.event.JdbcEventListener;
import com.codingapi.txlcn.tc.support.p6spy.common.PreparedStatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.common.ResultSetInformation;
import com.codingapi.txlcn.tc.support.p6spy.event.JdbcEventListener;
import java.io.InputStream;
import java.io.Reader;
......
......@@ -15,11 +15,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.wrapper;
package com.codingapi.txlcn.tc.support.p6spy.wrapper;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.ResultSetInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.event.JdbcEventListener;
import com.codingapi.txlcn.tc.support.p6spy.common.ResultSetInformation;
import com.codingapi.txlcn.tc.support.p6spy.event.JdbcEventListener;
import java.io.InputStream;
import java.io.Reader;
......
......@@ -15,11 +15,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.codingapi.txlcn.jdbcproxy.p6spy.wrapper;
package com.codingapi.txlcn.tc.support.p6spy.wrapper;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.ResultSetInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.common.StatementInformation;
import com.codingapi.txlcn.jdbcproxy.p6spy.event.JdbcEventListener;
import com.codingapi.txlcn.tc.support.p6spy.common.ResultSetInformation;
import com.codingapi.txlcn.tc.support.p6spy.common.StatementInformation;
import com.codingapi.txlcn.tc.support.p6spy.event.JdbcEventListener;
import java.sql.*;
......
<?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>tx-lcn</artifactId>
<groupId>com.codingapi.txlcn</groupId>
<version>5.0.0.RC2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>tx-jdbcproxy-p6spy</artifactId>
<dependencies>
<dependency>
<groupId>com.codingapi.txlcn</groupId>
<artifactId>tx-commons</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
<?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>tx-lcn</artifactId>
<groupId>com.codingapi.txlcn</groupId>
<version>5.0.0.RC2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>tx-spi-sleuth</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.spi.sleuth;
import brave.propagation.ExtraFieldPropagation;
import org.springframework.stereotype.Component;
/**
* Description:
* Company: CodingApi
* Date: 2018/11/29
*
* @author lorne
*/
@Component
public class TracerHelper {
/**
* 事务组标示Id
*/
public static final String GROUP_ID_FIELD_NAME = "groupId";
/**
* TxManager模块标示
*/
public static final String TX_MANAGER_FIELD_NAME = "txManager";
/**
* 模块标示
*/
public static final String TX_APP_LIST = "appList";
public void createAppList(String appList) {
ExtraFieldPropagation.set(TX_APP_LIST, appList);
}
public void createGroupId(String groupId) {
ExtraFieldPropagation.set(GROUP_ID_FIELD_NAME, groupId);
}
public void createManagerKey(String managerKey) {
ExtraFieldPropagation.set(TX_MANAGER_FIELD_NAME, managerKey);
}
public void createGroupId(String groupId, String managerKey) {
ExtraFieldPropagation.set(GROUP_ID_FIELD_NAME, groupId);
ExtraFieldPropagation.set(TX_MANAGER_FIELD_NAME, managerKey);
}
public String getGroupId() {
return ExtraFieldPropagation.get(GROUP_ID_FIELD_NAME);
}
public String getTxManagerKey() {
return ExtraFieldPropagation.get(TX_MANAGER_FIELD_NAME);
}
public String getAppList(){
return ExtraFieldPropagation.get(TX_APP_LIST);
}
}
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.spi.sleuth;
import com.codingapi.txlcn.spi.sleuth.listener.DefaultSleuthParamListener;
import com.codingapi.txlcn.spi.sleuth.listener.SleuthParamListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import java.util.Objects;
/**
* Description:
* Company: CodingApi
* Date: 2018/12/14
*
* @author lorne
*/
@Configuration
@ComponentScan
public class TxSleuthApiConfiguration {
static {
String propagationKeys = System.getProperty("spring.sleuth.propagation-keys");
if (Objects.isNull(propagationKeys)) {
propagationKeys = "";
} else if (!propagationKeys.trim().endsWith(",")) {
propagationKeys += ",";
}
System.setProperty("spring.sleuth.propagation-keys",
propagationKeys + TracerHelper.GROUP_ID_FIELD_NAME + ","
+ TracerHelper.TX_APP_LIST + "," + TracerHelper.TX_MANAGER_FIELD_NAME);
}
@Bean
@ConditionalOnMissingBean
public SleuthParamListener sleuthParamListener() {
return new DefaultSleuthParamListener();
}
}
\ No newline at end of file
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.spi.sleuth.listener;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Description:
* Company: CodingApi
* Date: 2018/12/13
*
* @author ujued
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AppServer {
/**
* app key
* example : 127.0.0.1:8080
*/
private String key;
/**
* 框架业务对象
*/
private Object server;
}
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.spi.sleuth.listener;
import com.codingapi.txlcn.spi.sleuth.TracerHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Arrays;
import java.util.List;
/**
* Description:
* Company: CodingApi
* Date: 2018/12/13
*
* @author ujued
*/
@Slf4j
public class DefaultSleuthParamListener implements SleuthParamListener {
@Autowired
private TracerHelper tracerHelper;
@Override
public List<String> beforeBalance(String localKey) {
String oldKey = tracerHelper.getAppList();
String val = oldKey;
if(oldKey==null){
val = localKey;
tracerHelper.createAppList(val);
}else{
if(!oldKey.contains(localKey)){
val = oldKey+","+localKey;
tracerHelper.createAppList(val);
}
}
return Arrays.asList(val.split(","));
}
@Override
public void afterNewBalance(String key) {
String oldKey = tracerHelper.getAppList();
tracerHelper.createAppList(oldKey+","+key);
}
}
/*
* Copyright 2017-2019 CodingApi .
*
* Licensed 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 com.codingapi.txlcn.spi.sleuth.listener;
import java.util.List;
/**
* Description:
* Company: CodingApi
* Date: 2018/12/13
*
* @author ujued
*/
public interface SleuthParamListener {
List<String> beforeBalance(String localKey);
void afterNewBalance(String key);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册