org.springframework.cloud.client.discovery.ReactiveDiscoveryClient Java Examples

The following examples show how to use org.springframework.cloud.client.discovery.ReactiveDiscoveryClient. 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
Source File: CachingServiceInstanceListSupplierTests.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Bean
public ReactiveDiscoveryClient reactiveDiscoveryClient() {
	return new ReactiveDiscoveryClient() {
		@Override
		public String description() {
			return SERVICE_ID;
		}

		@Override
		public Flux<ServiceInstance> getInstances(String serviceId) {
			return Flux.just(instance("1host", false),
					instance("2host-secure", true));
		}

		@Override
		public Flux<String> getServices() {
			return Flux.just(SERVICE_ID);
		}
	};
}
 
Example #2
Source File: CloudFoundryReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@Bean
public ReactiveDiscoveryClient customDiscoveryClient() {
	return new ReactiveDiscoveryClient() {
		@Override
		public String description() {
			return "Custom Reactive Discovery Client";
		}

		@Override
		public Flux<ServiceInstance> getInstances(String serviceId) {
			return Flux.empty();
		}

		@Override
		public Flux<String> getServices() {
			return Flux.empty();
		}
	};
}
 
Example #3
Source File: KubernetesReactiveDiscoveryClientTests.java    From spring-cloud-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnEmptyFluxWhenServiceHasNoSubsets(
		@Client KubernetesClient kubernetesClient,
		@Server KubernetesServer kubernetesServer) {
	kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services")
			.andReturn(200,
					new ServiceListBuilder().addNewItem().withNewMetadata()
							.withName("existing-service")
							.withLabels(new HashMap<String, String>() {
								{
									put("label", "value");
								}
							}).endMetadata().endItem().build())
			.once();

	KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties();
	ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(
			kubernetesClient, properties, KubernetesClient::services);
	Flux<ServiceInstance> instances = client.getInstances("existing-service");
	StepVerifier.create(instances).expectNextCount(0).expectComplete().verify();
}
 
Example #4
Source File: ReactiveCompositeDiscoveryClientAutoConfigurationTests.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Bean
ReactiveDiscoveryClient discoveryClient() {
	return new ReactiveDiscoveryClient() {
		@Override
		public String description() {
			return "Reactive Test Discovery Client";
		}

		@Override
		public Flux<ServiceInstance> getInstances(String serviceId) {
			return Flux.empty();
		}

		@Override
		public Flux<String> getServices() {
			return Flux.empty();
		}
	};
}
 
Example #5
Source File: CloudFoundryReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUseCustomServiceDiscovery() {
	contextRunner
			.withConfiguration(AutoConfigurations
					.of(ReactiveCommonsClientAutoConfiguration.class))
			.withUserConfiguration(
					CustomCloudFoundryReactiveDiscoveryClientConfiguration.class)
			.run(context -> {
				assertThat(context)
						.hasSingleBean(CloudFoundryReactiveHeartbeatSender.class);
				assertThat(context).getBeans(ReactiveDiscoveryClient.class)
						.hasSize(2);
				assertThat(context).hasBean("nativeCloudFoundryDiscoveryClient");
				assertThat(context)
						.hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
			});
}
 
Example #6
Source File: CloudFoundryReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUseAppServiceDiscovery() {
	contextRunner
			.withConfiguration(AutoConfigurations
					.of(ReactiveCommonsClientAutoConfiguration.class))
			.withPropertyValues("spring.cloud.cloudfoundry.discovery.use-dns=true",
					"spring.cloud.cloudfoundry.discovery.use-container-ip=false")
			.run(context -> {
				assertThat(context)
						.hasSingleBean(CloudFoundryReactiveHeartbeatSender.class);
				assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
				assertThat(context).hasBean("appServiceReactiveDiscoveryClient");
				assertThat(context)
						.hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
			});
}
 
Example #7
Source File: CloudFoundryReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUseDnsDiscovery() {
	contextRunner
			.withConfiguration(AutoConfigurations
					.of(ReactiveCommonsClientAutoConfiguration.class))
			.withPropertyValues("spring.cloud.cloudfoundry.discovery.use-dns=true",
					"spring.cloud.cloudfoundry.discovery.use-container-ip=true")
			.run(context -> {
				assertThat(context)
						.hasSingleBean(CloudFoundryReactiveHeartbeatSender.class);
				assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
				assertThat(context).hasBean("dnsBasedReactiveDiscoveryClient");
				assertThat(context)
						.hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
			});
}
 
Example #8
Source File: SimpleReactiveDiscoveryClientAutoConfigurationTests.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUseCustomConfiguration() {
	this.contextRunner.withUserConfiguration(Configuration.class)
			.withPropertyValues("spring.application.name=my-service",
					"spring.cloud.discovery.client.simple.order=1",
					"server.port=8443")
			.run((context) -> {
				ReactiveDiscoveryClient client = context
						.getBean(ReactiveDiscoveryClient.class);
				assertThat(client).isNotNull();
				assertThat(client.getOrder()).isEqualTo(1);
				InetUtils inet = context.getBean(InetUtils.class);
				assertThat(inet).isNotNull();
				SimpleReactiveDiscoveryProperties properties = context
						.getBean(SimpleReactiveDiscoveryProperties.class);
				assertThat(properties).isNotNull();
				assertThat(properties.getLocal().getServiceId())
						.isEqualTo("my-service");
				assertThat(properties.getLocal().getHost())
						.isEqualTo(inet.findFirstNonLoopbackHostInfo().getHostname());
				assertThat(properties.getLocal().getPort()).isEqualTo(8443);
			});
}
 
Example #9
Source File: SimpleReactiveDiscoveryClientAutoConfigurationTests.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUseDefaults() {
	this.contextRunner.run((context) -> {
		ReactiveDiscoveryClient client = context
				.getBean(ReactiveDiscoveryClient.class);
		assertThat(client).isNotNull();
		assertThat(client.getOrder())
				.isEqualTo(ReactiveDiscoveryClient.DEFAULT_ORDER);
		InetUtils inet = context.getBean(InetUtils.class);
		assertThat(inet).isNotNull();
		SimpleReactiveDiscoveryProperties properties = context
				.getBean(SimpleReactiveDiscoveryProperties.class);
		assertThat(properties).isNotNull();
		assertThat(properties.getLocal().getServiceId()).isEqualTo("application");
		assertThat(properties.getLocal().getHost())
				.isEqualTo(inet.findFirstNonLoopbackHostInfo().getHostname());
		assertThat(properties.getLocal().getPort()).isEqualTo(8080);
	});
}
 
Example #10
Source File: ReactiveDiscoveryClientHealthIndicator.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
private Mono<Health> doHealthCheck() {
	// @formatter:off
	return Mono.justOrEmpty(this.discoveryClient)
			.flatMapMany(ReactiveDiscoveryClient::getServices)
			.collectList()
			.defaultIfEmpty(emptyList())
			.map(services -> {
				ReactiveDiscoveryClient client = this.discoveryClient;
				String description = (this.properties.isIncludeDescription())
						? client.description() : "";
				return Health.status(new Status("UP", description))
						.withDetail("services", services).build();
			})
			.onErrorResume(exception -> {
				this.log.error("Error", exception);
				return Mono.just(Health.down().withException(exception).build());
			});
	// @formatter:on
}
 
Example #11
Source File: CachingServiceInstanceListSupplierTests.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Bean
ServiceInstanceListSupplier supplier(ConfigurableApplicationContext context,
		ReactiveDiscoveryClient discoveryClient,
		LoadBalancerProperties loadBalancerProperties,
		WebClient.Builder webClientBuilder) {
	DiscoveryClientServiceInstanceListSupplier firstDelegate = new DiscoveryClientServiceInstanceListSupplier(
			discoveryClient, context.getEnvironment());
	HealthCheckServiceInstanceListSupplier delegate = new TestHealthCheckServiceInstanceListSupplier(
			firstDelegate, loadBalancerProperties.getHealthCheck(),
			webClientBuilder.build());
	delegate.afterPropertiesSet();
	ObjectProvider<LoadBalancerCacheManager> cacheManagerProvider = context
			.getBeanProvider(LoadBalancerCacheManager.class);
	return new CachingServiceInstanceListSupplier(delegate,
			cacheManagerProvider.getIfAvailable());
}
 
Example #12
Source File: ConsulReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHaveDiscoveryClientWhenConsulDisabled() {
	contextRunner.withPropertyValues("spring.cloud.consul.enabled=false")
			.run(context -> {
				assertThat(context).doesNotHaveBean("consulReactiveDiscoveryClient");
				assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
				assertThat(context).doesNotHaveBean(
						ReactiveDiscoveryClientHealthIndicator.class);
			});
}
 
Example #13
Source File: EurekaReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHaveDiscoveryClientWhenEurekaClientDisabled() {
	contextRunner.withPropertyValues("eureka.client.enabled=false").run(context -> {
		assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
		assertThat(context)
				.doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
	});
}
 
Example #14
Source File: EurekaReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void worksWithoutWebflux() {
	contextRunner
			.withClassLoader(
					new FilteredClassLoader("org.springframework.web.reactive"))
			.run(context -> {
				assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
				assertThat(context).doesNotHaveBean(
						ReactiveDiscoveryClientHealthIndicator.class);
			});
}
 
Example #15
Source File: ConsulReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHaveDiscoveryClientWhenConsulDiscoveryDisabled() {
	contextRunner.withPropertyValues("spring.cloud.consul.discovery.enabled=false")
			.run(context -> {
				assertThat(context).doesNotHaveBean("consulReactiveDiscoveryClient");
				assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
				assertThat(context).doesNotHaveBean(
						ReactiveDiscoveryClientHealthIndicator.class);
			});
}
 
Example #16
Source File: EurekaReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHaveDiscoveryClientWhenDiscoveryDisabled() {
	contextRunner.withPropertyValues("spring.cloud.discovery.enabled=false")
			.run(context -> {
				assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
				assertThat(context).doesNotHaveBean(
						ReactiveDiscoveryClientHealthIndicator.class);
			});
}
 
Example #17
Source File: EurekaReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldWorkWithDefaults() {
	contextRunner.run(context -> {
		assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
		assertThat(context)
				.hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
	});
}
 
Example #18
Source File: ReactiveCompositeDiscoveryClientAutoConfigurationTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCreateCompositeReactiveDiscoveryClientWithDelegate() {
	this.contextRunner.withUserConfiguration(Configuration.class).run((context) -> {
		ReactiveDiscoveryClient client = context
				.getBean(ReactiveDiscoveryClient.class);
		assertThat(client).isNotNull();
		assertThat(client).isInstanceOf(ReactiveCompositeDiscoveryClient.class);
		assertThat(((ReactiveCompositeDiscoveryClient) client).getDiscoveryClients())
				.hasSize(1);
	});
}
 
Example #19
Source File: ConsulReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHaveDiscoveryClientWhenReactiveDiscoveryDisabled() {
	contextRunner.withPropertyValues("spring.cloud.discovery.reactive.enabled=false")
			.run(context -> {
				assertThat(context).doesNotHaveBean("consulReactiveDiscoveryClient");
				assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
				assertThat(context).doesNotHaveBean(
						ReactiveDiscoveryClientHealthIndicator.class);
			});
}
 
Example #20
Source File: ReactiveCompositeDiscoveryClientAutoConfigurationTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCreateCompositeReactiveDiscoveryClientWithoutDelegates() {
	this.contextRunner.run((context) -> {
		ReactiveDiscoveryClient client = context
				.getBean(ReactiveDiscoveryClient.class);
		assertThat(client).isNotNull();
		assertThat(client).isInstanceOf(ReactiveCompositeDiscoveryClient.class);
		assertThat(((ReactiveCompositeDiscoveryClient) client).getDiscoveryClients())
				.isEmpty();
	});
}
 
Example #21
Source File: ConsulReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
@Test
public void worksWithoutActuator() {
	contextRunner
			.withClassLoader(
					new FilteredClassLoader("org.springframework.boot.actuate"))
			.run(context -> {
				assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
				assertThat(context).doesNotHaveBean(
						ReactiveDiscoveryClientHealthIndicator.class);
			});
}
 
Example #22
Source File: ReactiveCompositeDiscoveryClient.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public Flux<String> getServices() {
	if (discoveryClients == null || discoveryClients.isEmpty()) {
		return Flux.empty();
	}
	return Flux.fromIterable(discoveryClients)
			.flatMap(ReactiveDiscoveryClient::getServices);
}
 
Example #23
Source File: ReactiveCompositeDiscoveryClient.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public Flux<ServiceInstance> getInstances(String serviceId) {
	if (discoveryClients == null || discoveryClients.isEmpty()) {
		return Flux.empty();
	}
	List<Flux<ServiceInstance>> serviceInstances = new ArrayList<>();
	for (ReactiveDiscoveryClient discoveryClient : discoveryClients) {
		serviceInstances.add(discoveryClient.getInstances(serviceId));
	}
	return CloudFlux.firstNonEmpty(serviceInstances);
}
 
Example #24
Source File: CloudFoundryReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHaveDiscoveryClientsWhenDiscoveryDisabled() {
	contextRunner.withPropertyValues("spring.cloud.discovery.enabled=false")
			.run(context -> {
				assertThat(context).doesNotHaveBean("cloudFoundryHeartbeatSender");
				assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
				assertThat(context).doesNotHaveBean(
						ReactiveDiscoveryClientHealthIndicator.class);
			});
}
 
Example #25
Source File: EurekaReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void worksWithoutActuator() {
	contextRunner
			.withClassLoader(
					new FilteredClassLoader("org.springframework.boot.actuate"))
			.run(context -> {
				assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
				assertThat(context).doesNotHaveBean(
						ReactiveDiscoveryClientHealthIndicator.class);
			});
}
 
Example #26
Source File: CloudFoundryReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHaveDiscoveryClientsWhenReactiveDiscoveryDisabled() {
	contextRunner.withPropertyValues("spring.cloud.discovery.reactive.enabled=false")
			.run(context -> {
				assertThat(context).doesNotHaveBean("cloudFoundryHeartbeatSender");
				assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
				assertThat(context).doesNotHaveBean(
						ReactiveDiscoveryClientHealthIndicator.class);
			});
}
 
Example #27
Source File: ConsulReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldWorkWithDefaults() {
	contextRunner.run(context -> {
		assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
		assertThat(context)
				.hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
	});
}
 
Example #28
Source File: ConsulReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHaveDiscoveryClientWhenDiscoveryDisabled() {
	contextRunner.withPropertyValues("spring.cloud.discovery.enabled=false")
			.run(context -> {
				assertThat(context).doesNotHaveBean("consulReactiveDiscoveryClient");
				assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
				assertThat(context).doesNotHaveBean(
						ReactiveDiscoveryClientHealthIndicator.class);
			});
}
 
Example #29
Source File: CloudFoundryReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHaveDiscoveryClientsWhenCloudFoundryDiscoveryDisabled() {
	contextRunner
			.withPropertyValues("spring.cloud.cloudfoundry.discovery.enabled=false")
			.run(context -> {
				assertThat(context).doesNotHaveBean("cloudFoundryHeartbeatSender");
				assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
				assertThat(context).doesNotHaveBean(
						ReactiveDiscoveryClientHealthIndicator.class);
			});
}
 
Example #30
Source File: ConsulReactiveDiscoveryClientConfigurationTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
@Test
public void worksWithoutWebflux() {
	contextRunner
			.withClassLoader(
					new FilteredClassLoader("org.springframework.web.reactive"))
			.run(context -> {
				assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
				assertThat(context).doesNotHaveBean(
						ReactiveDiscoveryClientHealthIndicator.class);
			});
}