-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support polaris registry Co-authored-by: liujianjun.ljj <[email protected]>
- Loading branch information
Showing
15 changed files
with
1,104 additions
and
4 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
86 changes: 86 additions & 0 deletions
86
example/src/test/java/com/alipay/sofa/rpc/polaris/PolarisBoltClientMain.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,86 @@ | ||
/* | ||
* 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.polaris; | ||
|
||
import com.alipay.sofa.rpc.config.ConsumerConfig; | ||
import com.alipay.sofa.rpc.config.RegistryConfig; | ||
import com.alipay.sofa.rpc.context.RpcRuntimeContext; | ||
import com.alipay.sofa.rpc.log.Logger; | ||
import com.alipay.sofa.rpc.log.LoggerFactory; | ||
import com.alipay.sofa.rpc.test.EchoService; | ||
import com.alipay.sofa.rpc.test.HelloService; | ||
|
||
/** | ||
* <p></p> | ||
* <p> | ||
* | ||
* | ||
* @author <a href=mailto:[email protected]>ZhangLibin</a> | ||
*/ | ||
public class PolarisBoltClientMain { | ||
|
||
/** | ||
* slf4j Logger for this class | ||
*/ | ||
private final static Logger LOGGER = LoggerFactory.getLogger(PolarisBoltClientMain.class); | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
|
||
RegistryConfig registryConfig = new RegistryConfig() | ||
.setProtocol("polaris") | ||
.setAddress("127.0.0.1:8091"); | ||
|
||
ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>() | ||
.setInterfaceId(HelloService.class.getName()) | ||
.setRegistry(registryConfig) | ||
.setTimeout(3000); | ||
HelloService helloService = consumerConfig.refer(); | ||
|
||
ConsumerConfig<EchoService> consumerConfig2 = new ConsumerConfig<EchoService>() | ||
.setInterfaceId(EchoService.class.getName()) | ||
.setRegistry(registryConfig) | ||
.setTimeout(3000); | ||
EchoService echoService = consumerConfig2.refer(); | ||
|
||
LOGGER.warn("started at pid {}", RpcRuntimeContext.PID); | ||
|
||
try { | ||
while (true) { | ||
try { | ||
String s = helloService.sayHello("xxx", 22); | ||
LOGGER.warn("{}", s); | ||
} catch (Exception e) { | ||
LOGGER.error(e.getMessage(), e); | ||
} | ||
try { | ||
Thread.sleep(2000); | ||
} catch (Exception e) { | ||
} | ||
} | ||
|
||
} catch (Exception e) { | ||
LOGGER.error("", e); | ||
} | ||
|
||
synchronized (PolarisBoltClientMain.class) { | ||
while (true) { | ||
PolarisBoltClientMain.class.wait(); | ||
} | ||
} | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
example/src/test/java/com/alipay/sofa/rpc/polaris/PolarisBoltServerMain.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,72 @@ | ||
/* | ||
* 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.polaris; | ||
|
||
import com.alipay.sofa.rpc.config.ProviderConfig; | ||
import com.alipay.sofa.rpc.config.RegistryConfig; | ||
import com.alipay.sofa.rpc.config.ServerConfig; | ||
import com.alipay.sofa.rpc.context.RpcRuntimeContext; | ||
import com.alipay.sofa.rpc.log.Logger; | ||
import com.alipay.sofa.rpc.log.LoggerFactory; | ||
import com.alipay.sofa.rpc.test.EchoService; | ||
import com.alipay.sofa.rpc.test.EchoServiceImpl; | ||
import com.alipay.sofa.rpc.test.HelloService; | ||
import com.alipay.sofa.rpc.test.HelloServiceImpl; | ||
|
||
/** | ||
* <p></p> | ||
* <p> | ||
* | ||
* | ||
* @author <a href=mailto:[email protected]>ZhangLibin</a> | ||
*/ | ||
public class PolarisBoltServerMain { | ||
|
||
/** | ||
* slf4j Logger for this class | ||
*/ | ||
private final static Logger LOGGER = LoggerFactory.getLogger(PolarisBoltServerMain.class); | ||
|
||
public static void main(String[] args) { | ||
|
||
RegistryConfig registryConfig = new RegistryConfig() | ||
.setProtocol("polaris") | ||
.setAddress("127.0.0.1:8091"); | ||
|
||
ServerConfig serverConfig = new ServerConfig() | ||
.setPort(22101) | ||
.setDaemon(false); | ||
|
||
ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>() | ||
.setInterfaceId(HelloService.class.getName()) | ||
.setRef(new HelloServiceImpl("result from 22101")) | ||
.setServer(serverConfig) | ||
.setRegistry(registryConfig); | ||
|
||
ProviderConfig<EchoService> providerConfig2 = new ProviderConfig<EchoService>() | ||
.setInterfaceId(EchoService.class.getName()) | ||
.setRef(new EchoServiceImpl()) | ||
.setServer(serverConfig) | ||
.setRegistry(registryConfig); | ||
|
||
providerConfig.export(); | ||
providerConfig2.export(); | ||
|
||
LOGGER.warn("started at pid {}", RpcRuntimeContext.PID); | ||
} | ||
|
||
} |
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,104 @@ | ||
<?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-registry</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
<artifactId>sofa-rpc-registry-polaris</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>sofa-rpc-log</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>sofa-rpc-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.tencent.polaris</groupId> | ||
<artifactId>polaris-discovery-factory</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.tencent.polaris</groupId> | ||
<artifactId>polaris-test-mock-discovery</artifactId> | ||
<scope>test</scope> | ||
</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.source}</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> |
45 changes: 45 additions & 0 deletions
45
...registry-polaris/src/main/java/com/alipay/sofa/rpc/registry/polaris/PolarisConstants.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,45 @@ | ||
/* | ||
* 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.registry.polaris; | ||
|
||
/** | ||
* constants of the polaris registry | ||
* | ||
* @author <a href=mailto:[email protected]>ZhangLibin</a> | ||
*/ | ||
public class PolarisConstants { | ||
|
||
public static final String POLARIS_SERVER_CONNECTOR_PROTOCOL_KEY = "connector.protocol"; | ||
|
||
public static final String HEALTH_CHECK_TTL_KEY = "healthCheck.ttl"; | ||
|
||
public static final String HEARTBEAT_INTERVAL_KEY = "heartbeat.interval"; | ||
|
||
public static final String HEARTBEAT_CORE_SIZE_KEY = "heartbeat.coreSize"; | ||
|
||
public static final String LOOKUP_INTERVAL_KEY = "lookup.interval"; | ||
|
||
public static final String POLARIS_SERVER_CONNECTOR_PROTOCOL = "grpc"; | ||
|
||
public static final int DEFAULT_HEALTH_CHECK_TTL = 10; | ||
|
||
public static final int DEFAULT_HEARTBEAT_INTERVAL = 3000; | ||
|
||
public static final int DEFAULT_HEARTBEAT_CORE_SIZE = 1; | ||
|
||
public static final int DEFAULT_LOOKUP_INTERVAL = 1000; | ||
} |
Oops, something went wrong.