-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support PolarisRegistryConfiguration (#1291)
* support PolarisRegistryConfiguration --------- Co-authored-by: 呈铭 <beck.wcm@antgroup.com>
- Loading branch information
1 parent
92efd61
commit 447b919
Showing
5 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...re/src/main/java/com/alipay/sofa/boot/autoconfigure/rpc/PolarisRegistryConfiguration.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,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(); | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
...-sofa-boot/src/main/java/com/alipay/sofa/rpc/boot/config/PolarisRegistryConfigurator.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,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; | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
.../src/test/java/com/alipay/sofa/rpc/boot/test/config/PolarisRegistryConfiguratorTests.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,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")); | ||
} | ||
} |