Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registry polaris #1147

Merged
merged 14 commits into from
Mar 7, 2022
8 changes: 7 additions & 1 deletion all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<bolt.swagger.version>1.5.18</bolt.swagger.version>
<httpclient.version>4.5.13</httpclient.version>
<httpcore.version>4.4.13</httpcore.version>
<grpc.version>1.28.0</grpc.version>
<grpc.version>1.33.0</grpc.version>
<guava.version>27.0-jre</guava.version>
<transmittable.version>2.12.1</transmittable.version>
</properties>
Expand Down Expand Up @@ -232,6 +232,11 @@
<artifactId>sofa-rpc-registry-sofa</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-registry-polaris</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-remoting-bolt</artifactId>
Expand Down Expand Up @@ -505,6 +510,7 @@
<include>com.alipay.sofa:sofa-rpc-registry-mesh</include>
<include>com.alipay.sofa:sofa-rpc-registry-multicast</include>
<include>com.alipay.sofa:sofa-rpc-registry-sofa</include>
<include>com.alipay.sofa:sofa-rpc-registry-polaris</include>
<include>com.alipay.sofa:sofa-rpc-remoting-bolt</include>
<include>com.alipay.sofa:sofa-rpc-remoting-http</include>
<include>com.alipay.sofa:sofa-rpc-remoting-resteasy</include>
Expand Down
15 changes: 14 additions & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<dubbo.version>2.6.7</dubbo.version>
<nacos.version>2.0.3</nacos.version>
<sofa.registry.version>5.2.0</sofa.registry.version>
<polaris.version>1.2.2</polaris.version>
<swagger.version>1.5.18</swagger.version>
<asm.version>7.0</asm.version>
<guava.version>27.0-jre</guava.version>
Expand All @@ -36,7 +37,7 @@
<jackson.databind.version>2.9.10.8</jackson.databind.version>
<msgpack.version>0.6.12</msgpack.version>
<protostuff.version>1.5.9</protostuff.version>
<grpc.version>1.28.0</grpc.version>
<grpc.version>1.33.0</grpc.version>

<!--common-->
<httpcore.version>4.4.13</httpcore.version>
Expand Down Expand Up @@ -521,6 +522,18 @@
<artifactId>jetty-alpn-openjdk8-client</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<!-- polaris client -->
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>polaris-discovery-factory</artifactId>
<version>${polaris.version}</version>
</dependency>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>polaris-test-mock-discovery</artifactId>
<version>${polaris.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
4 changes: 2 additions & 2 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<properties>
<protoc.version>3.11.0</protoc.version>
<protoc-gen-grpc-java.version>1.17.0</protoc-gen-grpc-java.version>
<sofa.rpc.compiler.version>0.0.2</sofa.rpc.compiler.version>
<grpc.version>1.28.0</grpc.version>
<sofa.rpc.compiler.version>0.0.3</sofa.rpc.compiler.version>
<grpc.version>1.33.0</grpc.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
</properties>

Expand Down
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();
}
}
}

}
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);
}

}
1 change: 1 addition & 0 deletions registry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<module>registry-mesh</module>
<module>registry-multicast</module>
<module>registry-sofa</module>
<module>registry-polaris</module>
</modules>

<dependencyManagement>
Expand Down
104 changes: 104 additions & 0 deletions registry/registry-polaris/pom.xml
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>
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;
}
Loading