chore(project): 添加项目配置文件和忽略规则
- 添加 Babel 配置文件支持 ES6+ 语法转换 - 添加 ESLint 忽略规则和配置文件 - 添加 Git 忽略规则文件 - 添加 Travis CI 配置文件 - 添加 1.4.2 版本变更日志文件 - 添加 Helm 图表辅助模板文件 - 添加 Helm 忽略规则文件
This commit is contained in:
47
integration/motan/pom.xml
Normal file
47
integration/motan/pom.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2019 Seata.io Group.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<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>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>seata-motan</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>seata-motan ${project.version}</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-tm</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.weibo</groupId>
|
||||
<artifactId>motan-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.weibo</groupId>
|
||||
<artifactId>motan-transport-netty</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* 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 io.seata.integration.motan;
|
||||
|
||||
import com.weibo.api.motan.common.MotanConstants;
|
||||
import com.weibo.api.motan.core.extension.Activation;
|
||||
import com.weibo.api.motan.core.extension.Scope;
|
||||
import com.weibo.api.motan.core.extension.Spi;
|
||||
import com.weibo.api.motan.filter.Filter;
|
||||
import com.weibo.api.motan.rpc.Caller;
|
||||
import com.weibo.api.motan.rpc.Request;
|
||||
import com.weibo.api.motan.rpc.Response;
|
||||
import io.seata.core.context.RootContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author slievrly
|
||||
*/
|
||||
@Spi(scope = Scope.SINGLETON)
|
||||
@Activation(key = {MotanConstants.NODE_TYPE_SERVICE, MotanConstants.NODE_TYPE_REFERER}, sequence = 100)
|
||||
public class MotanTransactionFilter implements Filter {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MotanTransactionFilter.class);
|
||||
|
||||
public MotanTransactionFilter(){}
|
||||
@Override
|
||||
public Response filter(final Caller<?> caller, final Request request) {
|
||||
String currentXid = RootContext.getXID();
|
||||
String requestXid = getRpcXid(request);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("xid in RootContext [" + currentXid + "] xid in Request [" + requestXid + "]");
|
||||
}
|
||||
boolean bind = false;
|
||||
if (currentXid != null) {
|
||||
request.getAttachments().put(RootContext.KEY_XID, currentXid);
|
||||
} else if (requestXid != null) {
|
||||
RootContext.bind(requestXid);
|
||||
bind = true;
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("bind [" + requestXid + "] to RootContext");
|
||||
}
|
||||
|
||||
}
|
||||
try {
|
||||
return caller.call(request);
|
||||
} finally {
|
||||
if (bind) {
|
||||
String unbindXid = RootContext.unbind();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("unbind [" + unbindXid + "] from RootContext");
|
||||
}
|
||||
if (!requestXid.equalsIgnoreCase(unbindXid)) {
|
||||
LOGGER.warn("xid has changed, during RPC from " + requestXid + " to " + unbindXid);
|
||||
if (unbindXid != null) {
|
||||
RootContext.bind(unbindXid);
|
||||
LOGGER.warn("bind [" + unbindXid + "] back to RootContext");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get rpc xid
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private String getRpcXid(Request request) {
|
||||
String rpcXid = request.getAttachments().get(RootContext.KEY_XID);
|
||||
if (rpcXid == null) {
|
||||
rpcXid = request.getAttachments().get(RootContext.KEY_XID.toLowerCase());
|
||||
}
|
||||
return rpcXid;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
io.seata.integration.motan.MotanTransactionFilter
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* 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 io.seata.integration.motan;
|
||||
|
||||
import com.weibo.api.motan.config.ProtocolConfig;
|
||||
import com.weibo.api.motan.config.RefererConfig;
|
||||
import com.weibo.api.motan.config.RegistryConfig;
|
||||
import com.weibo.api.motan.config.ServiceConfig;
|
||||
import io.seata.core.context.RootContext;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author slievrly
|
||||
*/
|
||||
class MotanTransactionFilterTest {
|
||||
|
||||
private static final String SERVICE_GROUP = "motan";
|
||||
private static final String SERVICE_VERSION = "1.0.0";
|
||||
private static final int SERVICE_PORT = 8004;
|
||||
private static final String PROTOCOL_ID = "motan";
|
||||
private static final String PROTOCOL_NAME = "motan";
|
||||
private static final String XID = "127.0.0.1:8091:87654321";
|
||||
private static final int REQUEST_TIMEOUT = 1000;
|
||||
|
||||
@Test
|
||||
void testGetProviderXID() {
|
||||
RootContext.bind(XID);
|
||||
providerStart();
|
||||
consumerStart();
|
||||
RootContext.unbind();
|
||||
}
|
||||
|
||||
public void providerStart() {
|
||||
ServiceConfig<XIDService> serviceConfig = new ServiceConfig<>();
|
||||
serviceConfig.setInterface(XIDService.class);
|
||||
serviceConfig.setRef(new XIDServiceImpl());
|
||||
serviceConfig.setGroup(SERVICE_GROUP);
|
||||
serviceConfig.setVersion(SERVICE_VERSION);
|
||||
RegistryConfig registryConfig = new RegistryConfig();
|
||||
registryConfig.setRegProtocol("local");
|
||||
registryConfig.setCheck(false);
|
||||
serviceConfig.setRegistry(registryConfig);
|
||||
ProtocolConfig protocol = new ProtocolConfig();
|
||||
protocol.setId(PROTOCOL_ID);
|
||||
protocol.setName(PROTOCOL_NAME);
|
||||
serviceConfig.setProtocol(protocol);
|
||||
serviceConfig.setExport("motan:" + SERVICE_PORT);
|
||||
serviceConfig.export();
|
||||
}
|
||||
|
||||
private void consumerStart() {
|
||||
RefererConfig<XIDService> refererConfig = new RefererConfig<>();
|
||||
refererConfig.setInterface(XIDService.class);
|
||||
refererConfig.setGroup(SERVICE_GROUP);
|
||||
refererConfig.setVersion(SERVICE_VERSION);
|
||||
refererConfig.setRequestTimeout(REQUEST_TIMEOUT);
|
||||
RegistryConfig registry = new RegistryConfig();
|
||||
refererConfig.setRegistry(registry);
|
||||
ProtocolConfig protocol = new ProtocolConfig();
|
||||
protocol.setId(PROTOCOL_ID);
|
||||
protocol.setName(PROTOCOL_NAME);
|
||||
refererConfig.setProtocol(protocol);
|
||||
refererConfig.setDirectUrl("localhost:" + SERVICE_PORT);
|
||||
XIDService service = refererConfig.getRef();
|
||||
Assertions.assertEquals(service.getXid(), XID);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* 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 io.seata.integration.motan;
|
||||
|
||||
/**
|
||||
* @author slievrly
|
||||
*/
|
||||
public interface XIDService {
|
||||
String getXid();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* 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 io.seata.integration.motan;
|
||||
|
||||
import io.seata.core.context.RootContext;
|
||||
|
||||
/**
|
||||
* @author slievrly
|
||||
*/
|
||||
public class XIDServiceImpl implements XIDService {
|
||||
|
||||
@Override
|
||||
public String getXid() {
|
||||
return RootContext.getXID();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user