Search in sources :

Example 1 with Registration

use of org.springframework.cloud.client.serviceregistry.Registration in project spring-cloud-alibaba by alibaba.

the class DubboServiceRegistrationAutoConfiguration method onServiceInstancePreRegistered.

@EventListener(ServiceInstancePreRegisteredEvent.class)
public void onServiceInstancePreRegistered(ServiceInstancePreRegisteredEvent event) {
    Registration registration = event.getSource();
    if (!DubboBootstrap.getInstance().isReady() || !DubboBootstrap.getInstance().isStarted()) {
        ServiceRegistry<Registration> registry = event.getRegistry();
        synchronized (registry) {
            registrations.putIfAbsent(registry, new HashSet<>());
            registrations.get(registry).add(registration);
        }
    } else {
        attachDubboMetadataServiceMetadata(registration);
    }
}
Also used : EurekaRegistration(org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration) EurekaAutoServiceRegistration(org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration) ConsulRegistration(org.springframework.cloud.consul.serviceregistry.ConsulRegistration) Registration(org.springframework.cloud.client.serviceregistry.Registration) EventListener(org.springframework.context.event.EventListener)

Example 2 with Registration

use of org.springframework.cloud.client.serviceregistry.Registration in project Sermant by huaweicloud.

the class RegistrationInterceptor method doBefore.

@Override
public ExecuteContext doBefore(ExecuteContext context) {
    if (!(context.getArguments()[0] instanceof Registration)) {
        return context;
    }
    fillClientInfo((Registration) context.getArguments()[0]);
    final RegisterCenterService service = ServiceManager.getService(RegisterCenterService.class);
    final FixedResult fixedResult = new FixedResult();
    service.register(fixedResult);
    if (fixedResult.isSkip()) {
        context.skip(fixedResult.getResult());
    }
    return context;
}
Also used : FixedResult(com.huawei.register.entity.FixedResult) Registration(org.springframework.cloud.client.serviceregistry.Registration) RegisterCenterService(com.huawei.register.services.RegisterCenterService)

Example 3 with Registration

use of org.springframework.cloud.client.serviceregistry.Registration in project spring-cloud-netflix by spring-cloud.

the class DiscoveryClientRouteLocatorTests method testIgnoredLocalServiceByDefault.

@Test
public void testIgnoredLocalServiceByDefault() {
    given(this.discovery.getServices()).willReturn(Collections.singletonList(MYSERVICE));
    Registration registration = new Registration() {

        @Override
        public String getServiceId() {
            return MYSERVICE;
        }

        @Override
        public String getHost() {
            return "localhost";
        }

        @Override
        public int getPort() {
            return 80;
        }

        @Override
        public boolean isSecure() {
            return false;
        }

        @Override
        public URI getUri() {
            return null;
        }

        @Override
        public Map<String, String> getMetadata() {
            return null;
        }
    };
    DiscoveryClientRouteLocator routeLocator = new DiscoveryClientRouteLocator("/", this.discovery, this.properties, registration);
    LinkedHashMap<String, ZuulRoute> routes = routeLocator.locateRoutes();
    ZuulRoute actual = routes.get("/**");
    assertNull("routes didn't ignore " + MYSERVICE, actual);
    List<Route> routesMap = routeLocator.getRoutes();
    assertNotNull("routesMap was null", routesMap);
    assertTrue("routesMap was empty", routesMap.isEmpty());
}
Also used : ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) Registration(org.springframework.cloud.client.serviceregistry.Registration) Route(org.springframework.cloud.netflix.zuul.filters.Route) ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) Test(org.junit.Test)

Example 4 with Registration

use of org.springframework.cloud.client.serviceregistry.Registration in project Sermant by huaweicloud.

the class RegisterServiceImpl method before.

@Override
public void before(Object obj, Method method, Object[] arguments, BeforeResult beforeResult) {
    final Object argument = arguments[0];
    if (argument instanceof ZookeeperRegistration) {
        ZookeeperRegistration instanceInfo = (ZookeeperRegistration) argument;
        // 存放当前服务实例, 仅初始化一次
        CurrentInstance.newInstance(instanceInfo.getServiceId(), instanceInfo.getHost(), instanceInfo.getPort());
    } else if (argument instanceof Registration) {
        Registration instanceInfo = (Registration) argument;
        Map<String, String> meta = instanceInfo.getMetadata();
        meta.put(GrayConstant.GRAY_VERSION_KEY, PluginConfigManager.getPluginConfig(GrayConfig.class).getGrayVersion());
        // 存放当前服务实例, 仅初始化一次
        CurrentInstance.newInstance(instanceInfo.getServiceId(), instanceInfo.getHost(), instanceInfo.getPort());
    } else if (argument instanceof InstanceInfo) {
        InstanceInfo instanceInfo = (InstanceInfo) argument;
        // 存放当前服务实例, 初始化标签观察者
        CurrentInstance.newInstance(instanceInfo.getVIPAddress(), instanceInfo.getIPAddr(), instanceInfo.getPort());
    }
}
Also used : ZookeeperRegistration(org.springframework.cloud.zookeeper.serviceregistry.ZookeeperRegistration) GrayConfig(com.huawei.route.common.gray.config.GrayConfig) ServiceCombRegistration(com.huaweicloud.servicecomb.discovery.registry.ServiceCombRegistration) Registration(org.springframework.cloud.client.serviceregistry.Registration) ZookeeperRegistration(org.springframework.cloud.zookeeper.serviceregistry.ZookeeperRegistration) Map(java.util.Map) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 5 with Registration

use of org.springframework.cloud.client.serviceregistry.Registration in project Sermant by huaweicloud.

the class RegistrationInterceptor method doBefore.

@Override
public ExecuteContext doBefore(ExecuteContext context) {
    if (!(context.getArguments()[0] instanceof Registration)) {
        return context;
    }
    fillClientInfo((Registration) context.getArguments()[0]);
    final RegisterCenterService service = ServiceManager.getService(RegisterCenterService.class);
    final FixedResult fixedResult = new FixedResult();
    service.register(fixedResult);
    if (fixedResult.isSkip()) {
        context.skip(fixedResult.getResult());
    }
    return context;
}
Also used : FixedResult(com.huawei.registry.entity.FixedResult) Registration(org.springframework.cloud.client.serviceregistry.Registration) RegisterCenterService(com.huawei.registry.services.RegisterCenterService)

Aggregations

Registration (org.springframework.cloud.client.serviceregistry.Registration)6 EventListener (org.springframework.context.event.EventListener)2 NacosRegistration (com.alibaba.cloud.nacos.registry.NacosRegistration)1 FixedResult (com.huawei.register.entity.FixedResult)1 RegisterCenterService (com.huawei.register.services.RegisterCenterService)1 FixedResult (com.huawei.registry.entity.FixedResult)1 RegisterCenterService (com.huawei.registry.services.RegisterCenterService)1 GrayConfig (com.huawei.route.common.gray.config.GrayConfig)1 ServiceCombRegistration (com.huaweicloud.servicecomb.discovery.registry.ServiceCombRegistration)1 InstanceInfo (com.netflix.appinfo.InstanceInfo)1 Map (java.util.Map)1 Test (org.junit.Test)1 ConsulRegistration (org.springframework.cloud.consul.serviceregistry.ConsulRegistration)1 EurekaAutoServiceRegistration (org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration)1 EurekaRegistration (org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration)1 Route (org.springframework.cloud.netflix.zuul.filters.Route)1 ZuulRoute (org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute)1 ZookeeperRegistration (org.springframework.cloud.zookeeper.serviceregistry.ZookeeperRegistration)1