use of org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent in project incubator-servicecomb-java-chassis by apache.
the class TestMicroserviceVersions method onMicroserviceInstanceChangedNameNotMatch.
@Test
public void onMicroserviceInstanceChangedNameNotMatch() {
MicroserviceKey key = new MicroserviceKey();
key.setAppId(appId);
key.setServiceName("otherName");
MicroserviceInstanceChangedEvent event = new MicroserviceInstanceChangedEvent();
event.setKey(key);
eventBus.post(event);
Assert.assertEquals(0, pendingPullCount.get());
}
use of org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent in project incubator-servicecomb-java-chassis by apache.
the class ServiceRegistryClientImpl method watch.
public void watch(String selfMicroserviceId, AsyncResultCallback<MicroserviceInstanceChangedEvent> callback, AsyncResultCallback<Void> onOpen, AsyncResultCallback<Void> onClose) {
Boolean alreadyWatch = watchServices.get(selfMicroserviceId);
if (alreadyWatch == null) {
synchronized (ServiceRegistryClientImpl.class) {
alreadyWatch = watchServices.get(selfMicroserviceId);
if (alreadyWatch == null) {
watchServices.put(selfMicroserviceId, true);
String url = String.format(Const.REGISTRY_API.MICROSERVICE_WATCH, selfMicroserviceId);
IpPort ipPort = ipPortManager.getAvailableAddress();
WebsocketUtils.open(ipPort, url, o -> {
onOpen.success(o);
LOGGER.info("watching microservice {} successfully, " + "the chosen service center address is {}:{}", selfMicroserviceId, ipPort.getHostOrIp(), ipPort.getPort());
}, c -> {
watchErrorHandler(new ClientException("connection is closed accidentally"), selfMicroserviceId, callback);
onClose.success(null);
}, bodyBuffer -> {
MicroserviceInstanceChangedEvent response = null;
try {
response = JsonUtils.readValue(bodyBuffer.getBytes(), MicroserviceInstanceChangedEvent.class);
} catch (Exception e) {
LOGGER.error("watcher handle microservice {} response failed, {}", selfMicroserviceId, bodyBuffer.toString());
return;
}
try {
callback.success(response);
} catch (Exception e) {
LOGGER.error("notify watcher failed, microservice {}", selfMicroserviceId, e);
}
}, e -> {
watchErrorHandler(e, selfMicroserviceId, callback);
onClose.success(null);
}, f -> {
watchErrorHandler(f, selfMicroserviceId, callback);
});
}
}
}
}
Aggregations