Closed bwu41 closed 3 years ago
看了下源码,貌似不支持上面注册多个ip地址的写法:
/**
* SOFARegistry 配置
* <p>
* 配置格式: com.alipay.sofa.rpc.registry.address=sofa://xxx:9600?k1=v1
*
* @author <a href="mailto:zhiyuan.lzy@antfin.com">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);
}
@Override
public String registryType() {
return SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_SOFA;
}
}
public class RegistryParseUtil {
/**
* Parse address string.
*
* @param config the config
* @param protocol the protocol
* @return the string
*/
public static String parseAddress(String config, String protocol) {
String address = null;
if (StringUtils.isNotEmpty(config) && config.startsWith(protocol)) {
final String nacosProtocol = protocol + "://";
String value = config.substring(nacosProtocol.length());
if (!value.contains("?")) {
address = value;
} else {
int index = value.lastIndexOf('?');
address = value.substring(0, index);
}
}
return address;
}
/**
* Parse param map.
*
* @param address the address
* @param protocol the protocol
* @return the map
*/
public static Map<String, String> parseParam(String address, String protocol) {
String host = parseAddress(address, protocol);
//for config ?
String paramString = address.substring(address.indexOf(host) + host.length());
if (StringUtils.isNotEmpty(paramString) && paramString.startsWith("?")) {
paramString = paramString.substring(1);
}
Map<String, String> map = new HashMap<String, String>();
if (paramString.contains("&")) {
String[] paramSplit = paramString.split("&");
for (String param : paramSplit) {
Map<String, String> tempMap = parseKeyValue(param);
map.putAll(tempMap);
}
} else {
Map<String, String> tempMap = parseKeyValue(paramString);
map.putAll(tempMap);
}
return map;
}
}
是不是意味着只需要写入一个ip即可呢?
@bwu41 写一个即可,集群内地址有自发现机制。
@ujjboy 明白~ 谢谢!
按官网集成部署集群模式搭建了SOFA Registry 地址分别是:192.168.4.100, 192.168.4.101, 192.168.4.102
在项目application.properties中添加注册中心:
配置一台的时候可以成功
配置集群地址的时候 失败
或
com.alipay.sofa.rpc.registry.address=sofa://192.168.4.100:9603, 192.168.4.101:9603, 192.168.4.102:9603