Java Code Examples for org.springframework.cloud.client.discovery.DiscoveryClient

The following examples show how to use org.springframework.cloud.client.discovery.DiscoveryClient. 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 Health health() {
	Health.Builder builder = new Health.Builder();

	if (this.discoveryInitialized.get()) {
		try {
			DiscoveryClient client = this.discoveryClient.getIfAvailable();
			List<String> services = client.getServices();
			String description = (this.properties.isIncludeDescription())
					? client.description() : "";
			builder.status(new Status("UP", description)).withDetail("services",
					services);
		}
		catch (Exception e) {
			this.log.error("Error", e);
			builder.down(e);
		}
	}
	else {
		builder.status(new Status(Status.UNKNOWN.getCode(),
				"Discovery Client not initialized"));
	}
	return builder.build();
}
 
Example 2
@Bean
@ConditionalOnBean(DiscoveryClient.class)
@ConditionalOnMissingBean
public ServiceInstanceListSupplier zookeeperDiscoveryClientServiceInstanceListSupplier(
		DiscoveryClient discoveryClient, Environment env,
		ApplicationContext context,
		ZookeeperDependencies zookeeperDependencies) {
	DiscoveryClientServiceInstanceListSupplier firstDelegate = new DiscoveryClientServiceInstanceListSupplier(
			discoveryClient, env);
	ZookeeperServiceInstanceListSupplier secondDelegate = new ZookeeperServiceInstanceListSupplier(firstDelegate,
			zookeeperDependencies);
	ObjectProvider<LoadBalancerCacheManager> cacheManagerProvider = context
			.getBeanProvider(LoadBalancerCacheManager.class);
	if (cacheManagerProvider.getIfAvailable() != null) {
		return new CachingServiceInstanceListSupplier(secondDelegate,
				cacheManagerProvider.getIfAvailable());
	}
	return secondDelegate;
}
 
Example 3
public LightminApplicationDiscoveryListener(final DiscoveryClient discoveryClient,
                                            final DiscoveryRegistrationBean discoveryRegistrationBean,
                                            final HeartbeatMonitor heartbeatMonitor) {
    this.discoveryClient = discoveryClient;
    this.discoveryRegistrationBean = discoveryRegistrationBean;
    this.heartbeatMonitor = heartbeatMonitor;
}
 
Example 4
@BeforeEach
public void setup() {
    discoveryClient = mock(DiscoveryClient.class);
    authConfigurationProperties = new AuthConfigurationProperties();
    authConfigurationProperties.setProvider("DUMMY");
    authConfigurationProperties.setZosmfServiceId(AUTHORIZATION_SERVICE_ID); // Default based on the local configuration

    BuildInfo buildInfo = mock(BuildInfo.class);

    BuildInfoDetails buildInfoDetails = new BuildInfoDetails(new Properties(), new Properties());
    when(buildInfo.getBuildInfoDetails()).thenReturn(buildInfoDetails);

    gatewayHomepageController = new GatewayHomepageController(
        discoveryClient, authConfigurationProperties, buildInfo);
}
 
Example 5
public AbstractSpringCloudRegistry(URL url, DiscoveryClient discoveryClient,
		DubboServiceMetadataRepository dubboServiceMetadataRepository,
		DubboMetadataServiceProxy dubboMetadataConfigServiceProxy,
		JSONUtils jsonUtils, DubboGenericServiceFactory dubboGenericServiceFactory,
		ConfigurableApplicationContext applicationContext) {
	super(url);
	this.servicesLookupInterval = url
			.getParameter(SERVICES_LOOKUP_INTERVAL_PARAM_NAME, 60L);
	this.discoveryClient = discoveryClient;
	this.repository = dubboServiceMetadataRepository;
	this.dubboMetadataConfigServiceProxy = dubboMetadataConfigServiceProxy;
	this.jsonUtils = jsonUtils;
	this.dubboGenericServiceFactory = dubboGenericServiceFactory;
	this.applicationContext = applicationContext;
}
 
Example 6
@Bean
DiscoveryClient discoveryClient() {

	DiscoveryClient mock = Mockito.mock(DiscoveryClient.class);
	when(mock.getInstances(anyString())).thenReturn(Collections.singletonList(
			new SimpleServiceInstance(URI.create("https://foo:1234"))));

	return mock;
}
 
Example 7
StubRunnerDiscoveryClient(DiscoveryClient delegate, StubFinder stubFinder,
		StubMapperProperties stubMapperProperties, String springAppName) {
	this.delegate = delegate instanceof StubRunnerDiscoveryClient
			? noOpDiscoveryClient() : delegate;
	if (log.isDebugEnabled()) {
		log.debug("Will delegate calls to discovery service [" + this.delegate
				+ "] if a stub is not found");
	}
	this.stubFinder = stubFinder;
	this.stubMapperProperties = stubMapperProperties;
}
 
Example 8
@Bean
@ConditionalOnBean(DiscoveryClient.class)
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations",
		havingValue = "health-check")
public ServiceInstanceListSupplier healthCheckDiscoveryClientServiceInstanceListSupplier(
		ConfigurableApplicationContext context) {
	return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient()
			.withHealthChecks().withCaching().build(context);
}
 
Example 9
Source Project: dts   Source File: DtsLoadbalance.java    License: Apache License 2.0 5 votes vote down vote up
public DtsLoadbalance(DiscoveryClient discoveryClient) {
    SCHEDULE_EXCUTOR.scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            try {
                serviceInstanceList = discoveryClient.getInstances(RemoteConstant.DTS_SERVER_NAME);
                size = serviceInstanceList.size();
            } catch (Throwable e) {
                LOGGER.error(e.getMessage(), e);
            }
        }
    }, 0, INTERVAL, TimeUnit.MINUTES);
}
 
Example 10
@Bean
@ConditionalOnMissingBean(DiscoveryClient.class)
@ConditionalOnStubbedDiscoveryEnabled
@ConditionalOnProperty(value = "stubrunner.cloud.delegate.enabled",
		havingValue = "false", matchIfMissing = true)
public DiscoveryClient noOpStubRunnerDiscoveryClient(StubFinder stubFinder,
		StubMapperProperties stubMapperProperties,
		@Value("${spring.application.name:unknown}") String springAppName) {
	return new StubRunnerDiscoveryClient(stubFinder, stubMapperProperties,
			springAppName);
}
 
Example 11
@Bean
public LightminApplicationDiscoveryListener lightminApplicationDiscoveryListener(
        final DiscoveryClient discoveryClient,
        final DiscoveryRegistrationBean discoveryRegistrationBean,
        final HeartbeatMonitor heartbeatMonitor) {
    return new LightminApplicationDiscoveryListener(discoveryClient, discoveryRegistrationBean, heartbeatMonitor);
}
 
Example 12
Source Project: Moss   Source File: InstanceDiscoveryListener.java    License: Apache License 2.0 5 votes vote down vote up
public InstanceDiscoveryListener(DiscoveryClient discoveryClient,
                                 InstanceRegistry registry,
                                 InstanceRepository repository) {
    this.discoveryClient = discoveryClient;
    this.registry = registry;
    this.repository = repository;
}
 
Example 13
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties(prefix = "spring.boot.admin.discovery")
public InstanceDiscoveryListener instanceDiscoveryListener(ServiceInstanceConverter serviceInstanceConverter,
                                                           DiscoveryClient discoveryClient,
                                                           InstanceRegistry registry,
                                                           InstanceRepository repository) {
    InstanceDiscoveryListener listener = new InstanceDiscoveryListener(discoveryClient, registry, repository);
    listener.setConverter(serviceInstanceConverter);
    return listener;
}
 
Example 14
Source Project: Moss   Source File: InstanceDiscoveryListenerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    discovery = mock(DiscoveryClient.class);
    InstanceRepository repository = new EventsourcingInstanceRepository(new InMemoryEventStore());
    registry = spy(new InstanceRegistry(repository, new HashingInstanceUrlIdGenerator()));
    listener = new InstanceDiscoveryListener(discovery, registry, repository);
}
 
Example 15
Source Project: tutorials   Source File: UaaSignatureVerifierClient.java    License: MIT License 5 votes vote down vote up
public UaaSignatureVerifierClient(DiscoveryClient discoveryClient, @Qualifier("loadBalancedRestTemplate") RestTemplate restTemplate,
                              OAuth2Properties oAuth2Properties) {
    this.restTemplate = restTemplate;
    this.oAuth2Properties = oAuth2Properties;
    // Load available UAA servers
    discoveryClient.getServices();
}
 
Example 16
@Bean
LandscapeWatcher landscapeWatcher(DiscoveryClient discoveryClient, CatalogService catalogService,
		List<ApplicationFilter> applicationFilters,
		List<ApplicationInstanceFilter> applicationInstanceFilters,
		ApplicationEventPublisher publisher) {
	return new LandscapeWatcher(discoveryClient, catalogService,
			applicationFilters, applicationInstanceFilters, publisher);
}
 
Example 17
Source Project: cubeai   Source File: UaaSignatureVerifierClient.java    License: Apache License 2.0 5 votes vote down vote up
public UaaSignatureVerifierClient(DiscoveryClient discoveryClient, @Qualifier("loadBalancedRestTemplate") RestTemplate restTemplate,
                              OAuth2Properties oAuth2Properties) {
    this.restTemplate = restTemplate;
    this.oAuth2Properties = oAuth2Properties;
    // Load available UAA servers
    discoveryClient.getServices();
}
 
Example 18
Source Project: cubeai   Source File: UaaSignatureVerifierClient.java    License: Apache License 2.0 5 votes vote down vote up
public UaaSignatureVerifierClient(DiscoveryClient discoveryClient, @Qualifier("loadBalancedRestTemplate") RestTemplate restTemplate,
                              OAuth2Properties oAuth2Properties) {
    this.restTemplate = restTemplate;
    this.oAuth2Properties = oAuth2Properties;
    // Load available UAA servers
    discoveryClient.getServices();
}
 
Example 19
Source Project: cubeai   Source File: UaaSignatureVerifierClient.java    License: Apache License 2.0 5 votes vote down vote up
public UaaSignatureVerifierClient(DiscoveryClient discoveryClient, @Qualifier("loadBalancedRestTemplate") RestTemplate restTemplate,
                              OAuth2Properties oAuth2Properties) {
    this.restTemplate = restTemplate;
    this.oAuth2Properties = oAuth2Properties;
    // Load available UAA servers
    discoveryClient.getServices();
}
 
Example 20
Source Project: cubeai   Source File: UaaSignatureVerifierClient.java    License: Apache License 2.0 5 votes vote down vote up
public UaaSignatureVerifierClient(DiscoveryClient discoveryClient, @Qualifier("loadBalancedRestTemplate") RestTemplate restTemplate,
                              OAuth2Properties oAuth2Properties) {
    this.restTemplate = restTemplate;
    this.oAuth2Properties = oAuth2Properties;
    // Load available UAA servers
    discoveryClient.getServices();
}
 
Example 21
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties(prefix = "spring.boot.admin.discovery")
public InstanceDiscoveryListener instanceDiscoveryListener(ServiceInstanceConverter serviceInstanceConverter,
		DiscoveryClient discoveryClient, InstanceRegistry registry, InstanceRepository repository) {
	InstanceDiscoveryListener listener = new InstanceDiscoveryListener(discoveryClient, registry, repository);
	listener.setConverter(serviceInstanceConverter);
	return listener;
}
 
Example 22
Source Project: cubeai   Source File: UaaSignatureVerifierClient.java    License: Apache License 2.0 5 votes vote down vote up
public UaaSignatureVerifierClient(DiscoveryClient discoveryClient, @Qualifier("loadBalancedRestTemplate") RestTemplate restTemplate,
                              OAuth2Properties oAuth2Properties) {
    this.restTemplate = restTemplate;
    this.oAuth2Properties = oAuth2Properties;
    // Load available UAA servers
    discoveryClient.getServices();
}
 
Example 23
Source Project: cubeai   Source File: UaaSignatureVerifierClient.java    License: Apache License 2.0 5 votes vote down vote up
public UaaSignatureVerifierClient(DiscoveryClient discoveryClient, @Qualifier("loadBalancedRestTemplate") RestTemplate restTemplate,
                              OAuth2Properties oAuth2Properties) {
    this.restTemplate = restTemplate;
    this.oAuth2Properties = oAuth2Properties;
    // Load available UAA servers
    discoveryClient.getServices();
}
 
Example 24
@Test
public void testUseDnsFalse() {
	this.contextRunner.withUserConfiguration(CloudFoundryConfig.class)
			.withPropertyValues("spring.cloud.cloudfoundry.discovery.use-dns=false")
			.run((context) -> {
				DiscoveryClient discoveryClient = context
						.getBean(DiscoveryClient.class);
				assertThat(discoveryClient.getClass())
						.isEqualTo(CloudFoundryDiscoveryClient.class);
			});
}
 
Example 25
@Test
public void discovery_client_is_zookeeper() {
	// given: this.discoveryClient
	// expect:
	then(discoveryClient).isInstanceOf(CompositeDiscoveryClient.class);
	CompositeDiscoveryClient composite = (CompositeDiscoveryClient) discoveryClient;
	List<DiscoveryClient> discoveryClients = composite.getDiscoveryClients();
	DiscoveryClient first = discoveryClients.get(0);
	then(first).isInstanceOf(ZookeeperDiscoveryClient.class);
}
 
Example 26
@Bean
@ConditionalOnBean(DiscoveryClient.class)
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations",
		havingValue = "zone-preference")
public ServiceInstanceListSupplier zonePreferenceDiscoveryClientServiceInstanceListSupplier(
		ConfigurableApplicationContext context) {
	return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient()
			.withZonePreference().withCaching().build(context);
}
 
Example 27
@Test
public void shouldNotHaveDiscoveryClientWhenBlockingDiscoveryDisabled() {
	new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
					DiscoveryClientOptionalArgsConfiguration.class,
					EurekaClientAutoConfiguration.class,
					EurekaDiscoveryClientConfiguration.class))
			.withPropertyValues("spring.cloud.discovery.blocking.enabled=false")
			.run(context -> {
				assertThat(context).doesNotHaveBean(DiscoveryClient.class);
				assertThat(context)
						.doesNotHaveBean(DiscoveryClientHealthIndicator.class);
			});
}
 
Example 28
Source Project: brpc-java   Source File: SpringCloudNamingService.java    License: Apache License 2.0 5 votes vote down vote up
public SpringCloudNamingService(BrpcURL namingUrl) {
    this.updateInterval = Constants.DEFAULT_INTERVAL;
    namingServiceTimer = new HashedWheelTimer(new CustomThreadFactory("namingService-timer-thread"));
    discoveryClient = BrpcApplicationContextUtils.getBean("discoveryClient", DiscoveryClient.class);
    if (discoveryClient == null) {
        throw new RuntimeException("discovery client is null");
    }
}
 
Example 29
@Bean
@ConditionalOnProperty(
		value = "spring.cloud.cloudfoundry.discovery.use-container-ip",
		havingValue = "true")
@ConditionalOnMissingBean(DiscoveryClient.class)
public SimpleDnsBasedDiscoveryClient discoveryClient(
		ObjectProvider<ServiceIdToHostnameConverter> provider,
		CloudFoundryDiscoveryProperties properties) {
	ServiceIdToHostnameConverter converter = provider.getIfAvailable();
	return converter == null ? new SimpleDnsBasedDiscoveryClient(properties)
			: new SimpleDnsBasedDiscoveryClient(properties, converter);
}
 
Example 30
@Test
public void onWhenRequested() throws Exception {
	setup("server.port=7000", "spring.cloud.config.discovery.enabled=true",
			"spring.cloud.kubernetes.discovery.enabled:true",
			"spring.cloud.kubernetes.enabled:true", "spring.application.name:test",
			"spring.cloud.config.discovery.service-id:configserver");
	assertEquals(1, this.context.getParent()
			.getBeanNamesForType(DiscoveryClient.class).length);
	DiscoveryClient client = this.context.getParent().getBean(DiscoveryClient.class);
	verify(client, atLeast(2)).getInstances("configserver");
	ConfigClientProperties locator = this.context
			.getBean(ConfigClientProperties.class);
	assertEquals("http://fake:8888/", locator.getUri()[0]);
}