Search in sources :

Example 6 with MicroserviceInstanceChangedEvent

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());
}
Also used : MicroserviceInstanceChangedEvent(org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent) MicroserviceKey(org.apache.servicecomb.serviceregistry.api.MicroserviceKey) Test(org.junit.Test)

Example 7 with MicroserviceInstanceChangedEvent

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);
                });
            }
        }
    }
}
Also used : MicroserviceInstanceChangedEvent(org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException)

Aggregations

MicroserviceInstanceChangedEvent (org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent)7 MicroserviceKey (org.apache.servicecomb.serviceregistry.api.MicroserviceKey)4 Test (org.junit.Test)4 Subscribe (com.google.common.eventbus.Subscribe)2 Holder (javax.xml.ws.Holder)1 MockUp (mockit.MockUp)1 IpPort (org.apache.servicecomb.foundation.common.net.IpPort)1 AsyncResultCallback (org.apache.servicecomb.foundation.vertx.AsyncResultCallback)1 ClientException (org.apache.servicecomb.serviceregistry.client.ClientException)1 ExceptionEvent (org.apache.servicecomb.serviceregistry.task.event.ExceptionEvent)1 PullMicroserviceVersionsInstancesEvent (org.apache.servicecomb.serviceregistry.task.event.PullMicroserviceVersionsInstancesEvent)1 RecoveryEvent (org.apache.servicecomb.serviceregistry.task.event.RecoveryEvent)1