Java Code Examples for com.alibaba.nacos.api.naming.pojo.Instance#setInstanceId()
The following examples show how to use
com.alibaba.nacos.api.naming.pojo.Instance#setInstanceId() .
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: NamingServiceNacosImpl.java From chronus with Apache License 2.0 | 6 votes |
@Override public void registerNode() throws Exception { Instance instance = new Instance(); instance.setInstanceId(currentNode.getAddress()); instance.setIp(currentNode.getIp()); instance.setClusterName(currentNode.getCluster()); instance.setPort(currentNode.getPort()); Map<String, String> metadata = new HashMap<>(); metadata.put(ChronusConstants.HOST_NAME, currentNode.getHostName()); metadata.put(ChronusConstants.REGISTER_TIME, currentNode.getVersion()); metadata.put(ChronusConstants.CLUSTER, currentNode.getCluster()); if (Objects.equals(ChronusConstants.Y, currentNode.getEnableMaster())) { metadata.put(ChronusConstants.IS_MASTER, ChronusConstants.N); } metadata.put(ChronusConstants.ENABLE_MASTER, currentNode.getEnableMaster()); metadata.put(ChronusConstants.ENABLE_EXECUTOR, currentNode.getEnableExecutor()); metadata.put(ChronusConstants.TAG, ChronusConstants.DEF_TAG); metadata.put(ChronusConstants.DATA_VERSION, currentNode.getVersion()); instance.setMetadata(metadata); nacosNamingService.registerInstance(ChronusConstants.NODE_NAME_CHRONUS, instance); //https://github.com/nacos-group/nacos-spring-project/issues/144 //namingMaintainService = NamingMaintainFactory.createMaintainService(environment.getProperty("nacos.discovery.server-addr")); }
Example 2
Source File: NacosNamingServiceUtils.java From dubbo-registry-nacos with Apache License 2.0 | 5 votes |
/** * Convert the {@link ServiceInstance} to {@link Instance} * * @param serviceInstance {@link ServiceInstance} * @return non-null * @since 2.7.5 */ public static Instance toInstance(ServiceInstance serviceInstance) { Instance instance = new Instance(); instance.setInstanceId(serviceInstance.getId()); instance.setServiceName(serviceInstance.getServiceName()); instance.setIp(serviceInstance.getHost()); instance.setPort(serviceInstance.getPort()); instance.setMetadata(serviceInstance.getMetadata()); instance.setEnabled(serviceInstance.isEnabled()); instance.setHealthy(serviceInstance.isHealthy()); return instance; }
Example 3
Source File: NacosMockTest.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
public static Instance serviceInstance(String serviceName, boolean isHealthy, Map<String, String> metadata) { Instance instance = new Instance(); instance.setInstanceId(UUID.randomUUID().toString()); instance.setServiceName(serviceName); instance.setHealthy(isHealthy); instance.setMetadata(metadata); return instance; }