org.springframework.cloud.client.discovery.simple.SimpleDiscoveryProperties Java Examples

The following examples show how to use org.springframework.cloud.client.discovery.simple.SimpleDiscoveryProperties. 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: AdminApplicationDiscoveryTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
private URI registerInstance() {
    //We register the instance by setting static values for the SimpleDiscoveryClient and issuing a
    //InstanceRegisteredEvent that makes sure the instance gets registered.
    SimpleDiscoveryProperties.SimpleServiceInstance serviceInstance = new SimpleDiscoveryProperties.SimpleServiceInstance();
    serviceInstance.setServiceId("Test-Instance");
    serviceInstance.setUri(URI.create("http://localhost:" + port));
    serviceInstance.getMetadata().put("management.context-path", "/mgmt");
    simpleDiscovery.getInstances().put("Test-Application", singletonList(serviceInstance));

    instance.publishEvent(new InstanceRegisteredEvent<>(new Object(), null));

    //To get the location of the registered instances we fetch the instance with the name.
    List<JSONObject> applications = webClient.get()
                                             .uri("/instances?name=Test-Instance")
                                             .accept(MediaType.APPLICATION_JSON)
                                             .exchange()
                                             .expectStatus()
                                             .isOk()
                                             .returnResult(JSONObject.class)
                                             .getResponseBody()
                                             .collectList()
                                             .block();
    assertThat(applications).hasSize(1);
    return URI.create("http://localhost:" + port + "/instances/" + applications.get(0).optString("id"));
}
 
Example #2
Source File: AdminApplicationDiscoveryTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
private URI registerInstance() {
	// We register the instance by setting static values for the SimpleDiscoveryClient
	// and issuing a
	// InstanceRegisteredEvent that makes sure the instance gets registered.
	SimpleDiscoveryProperties.SimpleServiceInstance serviceInstance = new SimpleDiscoveryProperties.SimpleServiceInstance();
	serviceInstance.setServiceId("Test-Instance");
	serviceInstance.setUri(URI.create("http://localhost:" + this.port));
	serviceInstance.getMetadata().put("management.context-path", "/mgmt");
	this.simpleDiscovery.getInstances().put("Test-Application", singletonList(serviceInstance));

	this.instance.publishEvent(new InstanceRegisteredEvent<>(new Object(), null));

	// To get the location of the registered instances we fetch the instance with the
	// name.
	List<JSONObject> applications = this.webClient.get().uri("/instances?name=Test-Instance")
			.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().returnResult(JSONObject.class)
			.getResponseBody().collectList().block();
	assertThat(applications).hasSize(1);
	return URI.create("http://localhost:" + this.port + "/instances/" + applications.get(0).optString("id"));
}
 
Example #3
Source File: AdminApplicationDiscoveryTest.java    From Moss with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    instance = new SpringApplicationBuilder().sources(TestAdminApplication.class)
                                             .web(WebApplicationType.REACTIVE)
                                             .run("--server.port=0", "--management.endpoints.web.base-path=/mgmt",
                                                 "--endpoints.health.enabled=true", "--info.test=foobar",
                                                 "--eureka.client.enabled=false");

    simpleDiscovery = instance.getBean(SimpleDiscoveryProperties.class);

    this.port = instance.getEnvironment().getProperty("local.server.port", Integer.class, 0);
    this.webClient = createWebClient(this.port);
}
 
Example #4
Source File: BlockingLoadBalancerClientTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp() {
	properties.getInstances().put("myservice",
			Collections.singletonList(
					new SimpleDiscoveryProperties.SimpleServiceInstance(
							URI.create("https://test.example:9999"))));
}
 
Example #5
Source File: ReactorLoadBalancerExchangeFilterFunctionTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp() {
	SimpleDiscoveryProperties.SimpleServiceInstance instance = new SimpleDiscoveryProperties.SimpleServiceInstance();
	instance.setServiceId("testservice");
	instance.setUri(URI.create("http://localhost:" + this.port));
	this.properties.getInstances().put("testservice",
			Collections.singletonList(instance));
}
 
Example #6
Source File: AdminApplicationDiscoveryTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp() {
	this.instance = new SpringApplicationBuilder().sources(TestAdminApplication.class)
			.web(WebApplicationType.REACTIVE).run("--server.port=0", "--management.endpoints.web.base-path=/mgmt",
					"--endpoints.health.enabled=true", "--info.test=foobar", "--eureka.client.enabled=false",
					"--spring.cloud.kubernetes.discovery.enabled=false");

	this.simpleDiscovery = this.instance.getBean(SimpleDiscoveryProperties.class);

	this.port = this.instance.getEnvironment().getProperty("local.server.port", Integer.class, 0);
	this.webClient = createWebClient(this.port);
}