Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Support for sofa registry. (#166)
Browse files Browse the repository at this point in the history
* support for sofa registry

* fix case
  • Loading branch information
leizhiyuan authored Apr 11, 2019
1 parent d4d0374 commit 61d32e5
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public class SofaBootRpcConfigConstants {
public static final String REGISTRY_PROTOCOL_CONSUL = "consul";

public static final String REGISTRY_PROTOCOL_NACOS = "nacos";
//@since 5.5.2
public static final String REGISTRY_PROTOCOL_SOFA = "sofa";

/* server */
public static final String RPC_PROTOCOL_BOLT = "bolt";
Expand Down
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);
}
}
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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.alipay.sofa.rpc.boot.config.RegistryConfigureProcessor;
import com.alipay.sofa.rpc.boot.config.SofaBootRpcConfigConstants;
import com.alipay.sofa.rpc.boot.config.SofaBootRpcProperties;
import com.alipay.sofa.rpc.boot.config.SofaRegistryConfigurator;
import com.alipay.sofa.rpc.boot.config.ZookeeperConfigurator;
import com.alipay.sofa.rpc.boot.container.ConsumerConfigContainer;
import com.alipay.sofa.rpc.boot.container.ProviderConfigContainer;
Expand Down Expand Up @@ -111,6 +112,11 @@ public RegistryConfigureProcessor nacosConfigurator() {
return new NacosConfigurator();
}

@Bean
public RegistryConfigureProcessor sofaRegistryConfigurator() {
return new SofaRegistryConfigurator();
}

@Bean(name = "registryConfigMap")
public Map<String, RegistryConfigureProcessor> configureProcessorMap() {
Map<String, RegistryConfigureProcessor> map = new HashMap<String, RegistryConfigureProcessor>();
Expand All @@ -119,6 +125,8 @@ public Map<String, RegistryConfigureProcessor> configureProcessorMap() {
map.put(SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_MESH, meshConfigurator());
map.put(SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_CONSUL, consulConfigurator());
map.put(SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_NACOS, nacosConfigurator());
map.put(SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_SOFA, sofaRegistryConfigurator());

return map;
}

Expand Down

0 comments on commit 61d32e5

Please sign in to comment.