Java Code Examples for com.alibaba.nacos.api.naming.pojo.Instance#getMetadata()
The following examples show how to use
com.alibaba.nacos.api.naming.pojo.Instance#getMetadata() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DubboNacosRegistry.java From joyrpc with Apache License 2.0 | 6 votes |
@Override protected URL createShardUrl(String defProtocol, Instance instance) { Map<String, String> meta = instance.getMetadata(); String alias = meta.remove(DUBBO_GROUP_KEY); alias = alias == null ? ALIAS_OPTION.getValue() : alias; if (!instance.isEnabled() || !url.getString(ALIAS_OPTION).equals(alias)) { return null; } String protocol = meta.remove(DUBBO_PROTOCOL_KEY); protocol = protocol == null || protocol.isEmpty() ? defProtocol : protocol; String ifaceName = meta.remove(DUBBO_PATH_KEY); String serviceVersion = meta.remove(DUBBO_SERVICE_VERSION_KEY); //重置alias meta.put(ALIAS_OPTION.getName(), alias); //重置serviceVersion meta.put(SERVICE_VERSION_OPTION.getName(), serviceVersion); //创建URL return new URL(protocol, instance.getIp(), instance.getPort(), ifaceName, meta); }
Example 2
Source File: NacosRegistryHelper.java From sofa-rpc with Apache License 2.0 | 6 votes |
private static String convertInstanceToUrl(Instance instance) { Map<String, String> metaData = instance.getMetadata(); if (metaData == null) { metaData = new HashMap<String, String>(); } String uri = ""; String protocol = metaData.get(RpcConstants.CONFIG_KEY_PROTOCOL); if (StringUtils.isNotEmpty(protocol)) { uri = protocol + "://"; } uri += instance.getIp() + ":" + instance.getPort(); StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> entry : metaData.entrySet()) { sb.append("&").append(entry.getKey()).append("=").append(entry.getValue()); } if (sb.length() > 0) { uri += sb.replace(0, 1, "?").toString(); } return uri; }
Example 3
Source File: NacosServer.java From spring-cloud-alibaba with Apache License 2.0 | 6 votes |
public NacosServer(final Instance instance) { super(instance.getIp(), instance.getPort()); this.instance = instance; this.metaInfo = new MetaInfo() { @Override public String getAppName() { return instance.getServiceName(); } @Override public String getServerGroup() { return null; } @Override public String getServiceIdForDiscovery() { return null; } @Override public String getInstanceId() { return instance.getInstanceId(); } }; this.metadata = instance.getMetadata(); }
Example 4
Source File: NacosRegistry.java From joyrpc with Apache License 2.0 | 5 votes |
/** * 生成分片URL * * @param defProtocol * @param instance * @return */ protected URL createShardUrl(String defProtocol, Instance instance) { Map<String, String> meta = instance.getMetadata(); if (!instance.isEnabled() || !url.getString(ALIAS_OPTION).equals(meta.get(ALIAS_OPTION.getName()))) { return null; } String protocol = meta.remove(Constants.PROTOCOL_KEY); protocol = protocol == null || protocol.isEmpty() ? defProtocol : protocol; return new URL(protocol, instance.getIp(), instance.getPort(), this.getPath(), meta); }
Example 5
Source File: NacosRegistry.java From dubbo-registry-nacos with Apache License 2.0 | 5 votes |
private URL buildURL(Instance instance) { Map<String, String> metadata = instance.getMetadata(); String protocol = metadata.get(PROTOCOL_KEY); String path = metadata.get(PATH_KEY); return new URL(protocol, instance.getIp(), instance.getPort(), path, instance.getMetadata()); }