forked from sofastack/sofa-rpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support mosn * first router to mosn, support mosn * move mesh router package to mesh * add switcher
- Loading branch information
1 parent
d063253
commit 0169fbc
Showing
31 changed files
with
2,076 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>sofa-rpc-extension-impl</artifactId> | ||
<version>5.5.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>sofa-rpc-registry-mesh</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>sofa-rpc-extension-common</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<sourceDirectory>src/main/java</sourceDirectory> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>false</filtering> | ||
<includes> | ||
<include>**/**</include> | ||
</includes> | ||
</resource> | ||
</resources> | ||
<testSourceDirectory>src/test/java</testSourceDirectory> | ||
<testResources> | ||
<testResource> | ||
<directory>src/test/resources</directory> | ||
<filtering>false</filtering> | ||
<includes> | ||
<include>**/**</include> | ||
</includes> | ||
</testResource> | ||
</testResources> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
<encoding>${project.build.sourceEncoding}</encoding> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<configuration> | ||
<skip>${module.install.skip}</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<configuration> | ||
<skip>${module.deploy.skip}</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skipTests>${skipTests}</skipTests> | ||
<includes> | ||
<!-- 这里需要根据自己的需要指定要跑的单元测试 --> | ||
<include>**/*Test.java</include> | ||
</includes> | ||
<!-- 如无特殊需求,将forkMode设置为once --> | ||
<forkMode>once</forkMode> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
97 changes: 97 additions & 0 deletions
97
extension-impl/registry-mesh/src/main/java/com/alipay/sofa/rpc/client/router/MeshRouter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.alipay.sofa.rpc.client.router; | ||
|
||
import com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap; | ||
import com.alipay.sofa.rpc.client.AddressHolder; | ||
import com.alipay.sofa.rpc.client.ProviderInfo; | ||
import com.alipay.sofa.rpc.client.Router; | ||
import com.alipay.sofa.rpc.common.RpcConstants; | ||
import com.alipay.sofa.rpc.common.utils.StringUtils; | ||
import com.alipay.sofa.rpc.config.ConsumerConfig; | ||
import com.alipay.sofa.rpc.config.RegistryConfig; | ||
import com.alipay.sofa.rpc.core.request.SofaRequest; | ||
import com.alipay.sofa.rpc.ext.Extension; | ||
import com.alipay.sofa.rpc.filter.AutoActive; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* 从mesh获取路由,只为 bolt 开启。 | ||
* <p> | ||
* | ||
* @author <a href="mailto:[email protected]">zhiyuan.lzy</a> | ||
*/ | ||
@Extension(value = "mesh", order = -19000) | ||
@AutoActive(consumerSide = true) | ||
public class MeshRouter extends Router { | ||
|
||
/** | ||
* 路由路径:注册中心 | ||
* | ||
* @since 5.5.0 | ||
*/ | ||
public static final String RPC_MESH_ROUTER = "MESH"; | ||
|
||
/** | ||
* 服务消费者配置 | ||
*/ | ||
protected ConsumerBootstrap consumerBootstrap; | ||
|
||
@Override | ||
public void init(ConsumerBootstrap consumerBootstrap) { | ||
this.consumerBootstrap = consumerBootstrap; | ||
} | ||
|
||
@Override | ||
public boolean needToLoad(ConsumerBootstrap consumerBootstrap) { | ||
ConsumerConfig consumerConfig = consumerBootstrap.getConsumerConfig(); | ||
// 不是直连,且从注册中心订阅配置 | ||
final boolean isDirect = StringUtils.isNotBlank(consumerConfig.getDirectUrl()); | ||
final List<RegistryConfig> registrys = consumerConfig.getRegistry(); | ||
boolean isMesh = false; | ||
|
||
if (registrys != null) { | ||
for (RegistryConfig registry : registrys) { | ||
if (registry.getProtocol().equalsIgnoreCase(RpcConstants.REGISTRY_PROTOCOL_MESH)) { | ||
isMesh = true; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
boolean isBolt = consumerConfig.getProtocol().equalsIgnoreCase(RpcConstants.PROTOCOL_TYPE_BOLT); | ||
|
||
return !isDirect && isMesh && isBolt; | ||
} | ||
|
||
@Override | ||
public List<ProviderInfo> route(SofaRequest request, List<ProviderInfo> providerInfos) { | ||
AddressHolder addressHolder = consumerBootstrap.getCluster().getAddressHolder(); | ||
if (addressHolder != null) { | ||
List<ProviderInfo> current = addressHolder.getProviderInfos(RpcConstants.ADDRESS_DEFAULT_GROUP); | ||
if (providerInfos != null) { | ||
providerInfos.addAll(current); | ||
} else { | ||
providerInfos = current; | ||
} | ||
} | ||
recordRouterWay(RPC_MESH_ROUTER); | ||
return providerInfos; | ||
} | ||
|
||
} |
Oops, something went wrong.