Skip to content

Commit

Permalink
Support PolarisRegistryConfiguration (#1291)
Browse files Browse the repository at this point in the history
* support PolarisRegistryConfiguration

---------

Co-authored-by: 呈铭 <beck.wcm@antgroup.com>
  • Loading branch information
wangchengming666 and 呈铭 authored Feb 27, 2024
1 parent 92efd61 commit 447b919
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.boot.autoconfigure.rpc;

import com.alipay.sofa.boot.autoconfigure.condition.ConditionalOnSwitch;
import com.alipay.sofa.rpc.boot.config.PolarisRegistryConfigurator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author chengming
* @version PolarisRegistryConfiguration.java, v 0.1 2024年02月27日 4:02 PM chengming
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnSwitch(value = "rpcPolarisRegistryConfiguration")
public class PolarisRegistryConfiguration {

@Bean
@ConditionalOnMissingBean
public PolarisRegistryConfigurator polarisRegistryConfigurator() {
return new PolarisRegistryConfigurator();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static String[] registryConfigurationClass() {
MulticastRegistryConfiguration.class.getName(),
MeshRegistryConfiguration.class.getName(),
ConsulRegistryConfiguration.class.getName(),
SofaRegistryConfiguration.class.getName() };
SofaRegistryConfiguration.class.getName(),
PolarisRegistryConfiguration.class.getName() };
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.boot.config;

import com.alipay.sofa.rpc.boot.common.RegistryParseUtil;
import com.alipay.sofa.rpc.config.RegistryConfig;

import java.util.Map;

/**
* @author chengming
* @version PolarisRegistryConfigurator.java, v 0.1 2024年02月27日 3:52 PM chengming
*/
public class PolarisRegistryConfigurator implements RegistryConfigureProcessor {

public PolarisRegistryConfigurator() {
}

@Override
public RegistryConfig buildFromAddress(String address) {
String polarisAddress = RegistryParseUtil.parseAddress(address,
SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_POLARIS);
Map<String, String> map = RegistryParseUtil.parseParam(address,
SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_POLARIS);

return new RegistryConfig().setAddress(polarisAddress).setParameters(map)
.setProtocol(SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_POLARIS);
}

@Override
public String registryType() {
return SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_POLARIS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class SofaBootRpcConfigConstants {
//@since 5.5.2
public static final String REGISTRY_PROTOCOL_SOFA = "sofa";

public static final String REGISTRY_PROTOCOL_POLARIS = "polaris";

/* server */
public static final String RPC_PROTOCOL_BOLT = "bolt";
public static final String RPC_PROTOCOL_REST = "rest";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.boot.test.config;

import com.alipay.sofa.rpc.boot.config.PolarisRegistryConfigurator;
import com.alipay.sofa.rpc.config.RegistryConfig;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author chengming
* @version PolarisRegistryConfiguratorTests.java, v 0.1 2024年02月27日 4:04 PM chengming
*/
public class PolarisRegistryConfiguratorTests {

@Test
public void buildFromAddress() {
String address = "polaris://30.183.168.90:12202?cluster=test";

PolarisRegistryConfigurator polarisRegistryConfigurator = new PolarisRegistryConfigurator();
RegistryConfig registryConfig = polarisRegistryConfigurator.buildFromAddress(address);

assertThat(registryConfig).isNotNull();
assertThat("polaris").isEqualTo(registryConfig.getProtocol());
assertThat("30.183.168.90:12202").isEqualTo(registryConfig.getAddress());
assertThat(registryConfig.getParameters()).isNotNull();
assertThat("test").isEqualTo(registryConfig.getParameter("cluster"));
}
}

0 comments on commit 447b919

Please sign in to comment.