Java Code Examples for org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry

The following examples show how to use org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry. These examples are extracted from open source projects. 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
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    ConfigurableEnvironment environment = applicationContext.getEnvironment();
    applicationContext.getBeanFactory().addBeanPostProcessor(new InstantiationAwareBeanPostProcessorAdapter() {

        @Override
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            if (bean instanceof CloudEurekaClient) {
                CloudEurekaClient eurekaClient = (CloudEurekaClient)bean;
                try {
                    Field filedPublisher = ReflectionUtils.findField(CloudEurekaClient.class, "publisher",
                        ApplicationEventPublisher.class);
                    ReflectionUtils.makeAccessible(filedPublisher);
                    ApplicationEventPublisher publisher =
                        (ApplicationEventPublisher)ReflectionUtils.getField(filedPublisher, eurekaClient);
                    return new EurekaClientWrapper(eurekaClient, environment, publisher);
                } finally {
                    Method method = ReflectionUtils.findMethod(CloudEurekaClient.class, "cancelScheduledTasks");
                    ReflectionUtils.makeAccessible(method);
                    ReflectionUtils.invokeMethod(method, eurekaClient);
                    eurekaClient = null;
                }
            } else if (bean instanceof EurekaServiceRegistry) {
                EurekaServiceRegistry eurekaServiceRegistry = (EurekaServiceRegistry)bean;
                return new EurekaServiceRegistryWrapper(eurekaServiceRegistry, environment);
            } else if (bean instanceof EurekaInstanceConfigBean) {
                EurekaInstanceConfigBean instanceConfig = (EurekaInstanceConfigBean)bean;
                instanceConfig.setPreferIpAddress(true);
                return bean;
            } else {
                return bean;
            }
        }
    });
}
 
Example 2
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
@ConditionalOnProperty(
		value = "spring.cloud.service-registry.auto-registration.enabled",
		matchIfMissing = true)
public EurekaAutoServiceRegistration eurekaAutoServiceRegistration(
		ApplicationContext context, EurekaServiceRegistry registry,
		EurekaRegistration registration) {
	return new EurekaAutoServiceRegistration(context, registry, registration);
}
 
Example 3
@Test
public void eurekaConfigNotLoadedWhenDiscoveryClientDisabled() {
	TestPropertyValues.of("spring.cloud.discovery.enabled=false")
			.applyTo(this.context);
	setupContext(TestConfiguration.class);
	assertBeanNotPresent(EurekaClientConfigBean.class);
	assertBeanNotPresent(EurekaInstanceConfigBean.class);
	assertBeanNotPresent(DiscoveryClient.class);
	assertBeanNotPresent(EurekaServiceRegistry.class);
	assertBeanNotPresent(EurekaClient.class);
	assertBeanNotPresent(EurekaDiscoveryClientConfiguration.Marker.class);
}
 
Example 4
Source Project: Moss   Source File: MossEurekaAutoServiceRegistration.java    License: Apache License 2.0 4 votes vote down vote up
public MossEurekaAutoServiceRegistration(ApplicationContext context, EurekaServiceRegistry serviceRegistry, EurekaRegistration registration, EurekaRegistration registration1) {
    super(context, serviceRegistry, registration);
    this.registration = registration1;
}
 
Example 5
Source Project: Moss   Source File: MultRegisterCenterServerMgmtConfig.java    License: Apache License 2.0 4 votes vote down vote up
public EurekaServiceRegistry eurekaServiceRegistry() {
    return new EurekaServiceRegistry();
}
 
Example 6
Source Project: Moss   Source File: MultRegisterCenterServerMgmtConfig.java    License: Apache License 2.0 4 votes vote down vote up
public MossEurekaAutoServiceRegistration eurekaAutoServiceRegistration(ApplicationContext context, EurekaServiceRegistry registry,
                                                                       EurekaRegistration registration, EurekaRegistration registration1) {
    return new MossEurekaAutoServiceRegistration(context, registry, registration, registration1);
}
 
Example 7
@Override
public void afterPropertiesSet() throws Exception {
    eurekaServiceRegistry = applicationContext.getBean(EurekaServiceRegistry.class);
    eurekaRegistration = applicationContext.getBean(EurekaRegistration.class);
}
 
Example 8
@Bean
public EurekaServiceRegistry eurekaServiceRegistry() {
	return new EurekaServiceRegistry();
}