Java Code Examples for com.alibaba.nacos.api.naming.pojo.Instance#getIp()
The following examples show how to use
com.alibaba.nacos.api.naming.pojo.Instance#getIp() .
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()); }
Example 6
Source File: NacosNamingServiceUtils.java From dubbo-registry-nacos with Apache License 2.0 | 5 votes |
/** * Convert the {@link Instance} to {@link ServiceInstance} * * @param instance {@link Instance} * @return non-null * @since 2.7.5 */ public static ServiceInstance toServiceInstance(Instance instance) { DefaultServiceInstance serviceInstance = new DefaultServiceInstance(instance.getInstanceId(), instance.getServiceName(), instance.getIp(), instance.getPort()); serviceInstance.setMetadata(instance.getMetadata()); serviceInstance.setEnabled(instance.isEnabled()); serviceInstance.setHealthy(instance.isHealthy()); return serviceInstance; }
Example 7
Source File: NacosSyncToEurekaServiceImpl.java From nacos-sync with Apache License 2.0 | 5 votes |
private InstanceInfo buildSyncInstance(Instance instance, TaskDO taskDO) { DataCenterInfo dataCenterInfo = new MyDataCenterInfo(DataCenterInfo.Name.MyOwn); HashMap<String, String> metadata = new HashMap<>(16); metadata.put(SkyWalkerConstants.DEST_CLUSTERID_KEY, taskDO.getDestClusterId()); metadata.put(SkyWalkerConstants.SYNC_SOURCE_KEY, skyWalkerCacheServices.getClusterType(taskDO.getSourceClusterId()).getCode()); metadata.put(SkyWalkerConstants.SOURCE_CLUSTERID_KEY, taskDO.getSourceClusterId()); String homePageUrl = "http://" + instance.getIp() + ":" + instance.getPort(); String serviceName = taskDO.getServiceName(); return new InstanceInfo( instance.getIp() + ":" + serviceName + ":" + instance.getPort(), serviceName, null, instance.getIp(), null, new InstanceInfo.PortWrapper(true, instance.getPort()), null, homePageUrl, homePageUrl + "/info", homePageUrl + "/health", null, serviceName, serviceName, 1, dataCenterInfo, instance.getIp(), InstanceInfo.InstanceStatus.UP, InstanceInfo.InstanceStatus.UNKNOWN, null, new LeaseInfo(30, 90, 0L, 0L, 0L, 0L, 0L), false, metadata, System.currentTimeMillis(), System.currentTimeMillis(), null, null ); }
Example 8
Source File: InstanceUtils.java From chronus with Apache License 2.0 | 4 votes |
public static String getAddressByInstance(Instance instance) { return instance.getIp() + ":" + instance.getPort(); }
Example 9
Source File: NacosSyncToNacosServiceImpl.java From nacos-sync with Apache License 2.0 | 4 votes |
private String composeInstanceKey(Instance instance) { return instance.getIp() + ":" + instance.getPort(); }