This repository has been archived by the owner on May 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
101 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
47 changes: 47 additions & 0 deletions
47
sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/SofaRegistryConfigurator.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,47 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* SOFARegistry 配置 | ||
* <p> | ||
* 配置格式: com.alipay.sofa.rpc.registry.address=sofa://xxx:9600?k1=v1 | ||
* | ||
* @author <a href="mailto:[email protected]">LiWei</a> | ||
*/ | ||
public class SofaRegistryConfigurator implements RegistryConfigureProcessor { | ||
|
||
public SofaRegistryConfigurator() { | ||
} | ||
|
||
@Override | ||
public RegistryConfig buildFromAddress(String address) { | ||
String sofaRegistryAddress = RegistryParseUtil.parseAddress(address, | ||
SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_SOFA); | ||
Map<String, String> map = RegistryParseUtil.parseParam(address, | ||
SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_SOFA); | ||
|
||
return new RegistryConfig().setAddress(sofaRegistryAddress) | ||
.setProtocol(SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_SOFA) | ||
.setParameters(map); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...boot-core/src/test/java/com/alipay/sofa/rpc/boot/config/SofaRegistryConfiguratorTest.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.config; | ||
|
||
import com.alipay.sofa.rpc.config.RegistryConfig; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
/** | ||
* @author zhiyuan.lzy | ||
* @version $Id: SofaRegistryConfiguratorTest.java, v 0.1 2010-03-16 17:36 zhiyuan.lzy Exp $$ | ||
*/ | ||
public class SofaRegistryConfiguratorTest { | ||
|
||
@Test | ||
public void buildFromAddress() { | ||
String address = "sofa://127.0.0.1:9603?cluster=test"; | ||
|
||
SofaRegistryConfigurator sofaRegistryConfigurator = new SofaRegistryConfigurator(); | ||
RegistryConfig registryConfig = sofaRegistryConfigurator.buildFromAddress(address); | ||
|
||
assertNotNull(registryConfig); | ||
assertEquals("sofa", registryConfig.getProtocol()); | ||
assertEquals("127.0.0.1:9603", registryConfig.getAddress()); | ||
assertNotNull(registryConfig.getParameters()); | ||
assertEquals("test", registryConfig.getParameter("cluster")); | ||
} | ||
} |
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