use of com.alibaba.nacos.api.naming.pojo.Instance in project dubbo by alibaba.
the class NacosServiceDiscovery method doRegister.
@Override
public void doRegister(ServiceInstance serviceInstance) {
execute(namingService, service -> {
Instance instance = toInstance(serviceInstance);
appendPreservedParam(instance);
service.registerInstance(instance.getServiceName(), group, instance);
});
}
use of com.alibaba.nacos.api.naming.pojo.Instance in project dubbo by alibaba.
the class NacosRegistry method doUnregister.
@Override
public void doUnregister(final URL url) {
execute(namingService -> {
String serviceName = getServiceName(url);
Instance instance = createInstance(url);
namingService.deregisterInstance(serviceName, getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP), instance.getIp(), instance.getPort());
});
}
use of com.alibaba.nacos.api.naming.pojo.Instance in project dubbo by alibaba.
the class NacosRegistry method subscribeEventListener.
private void subscribeEventListener(String serviceName, final URL url, final NotifyListener listener) throws NacosException {
ConcurrentMap<NotifyListener, EventListener> listeners = nacosListeners.computeIfAbsent(url, k -> new ConcurrentHashMap<>());
EventListener nacosListener = listeners.computeIfAbsent(listener, k -> {
EventListener eventListener = event -> {
if (event instanceof NamingEvent) {
NamingEvent e = (NamingEvent) event;
List<Instance> instances = e.getInstances();
if (isServiceNamesWithCompatibleMode(url)) {
// Get all instances with corresponding serviceNames to avoid instance overwrite and but with empty instance mentioned
// in https://github.com/apache/dubbo/issues/5885 and https://github.com/apache/dubbo/issues/5899
NacosInstanceManageUtil.initOrRefreshServiceInstanceList(serviceName, instances);
instances = NacosInstanceManageUtil.getAllCorrespondingServiceInstanceList(serviceName);
}
notifySubscriber(url, listener, instances);
}
};
return eventListener;
});
namingService.subscribe(serviceName, getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP), nacosListener);
}
use of com.alibaba.nacos.api.naming.pojo.Instance in project dubbo by alibaba.
the class NacosServiceDiscovery method unregister.
@Override
public void unregister(ServiceInstance serviceInstance) throws RuntimeException {
execute(namingService, service -> {
Instance instance = toInstance(serviceInstance);
service.deregisterInstance(instance.getServiceName(), group, instance);
});
}
use of com.alibaba.nacos.api.naming.pojo.Instance in project dubbo by alibaba.
the class NacosNamingServiceUtils method toInstance.
/**
* 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;
}
Aggregations