Commit 1eec10c5 by Johannes Edmeier

Make ApplicationDiscoveryListener customizable

parent b107544a
......@@ -18,8 +18,9 @@ package de.codecentric.boot.admin.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration;
import org.springframework.context.annotation.Bean;
......@@ -29,7 +30,7 @@ import de.codecentric.boot.admin.discovery.ApplicationDiscoveryListener;
import de.codecentric.boot.admin.registry.ApplicationRegistry;
@Configuration
@ConditionalOnClass({ DiscoveryClient.class })
@ConditionalOnSingleCandidate(DiscoveryClient.class)
@ConditionalOnProperty(prefix = "spring.boot.admin.discovery", name = "enabled", matchIfMissing = true)
@AutoConfigureAfter({ NoopDiscoveryClientAutoConfiguration.class })
public class DiscoveryClientConfiguration {
......@@ -44,6 +45,7 @@ public class DiscoveryClientConfiguration {
private ApplicationRegistry registry;
@Bean
@ConditionalOnMissingBean
public ApplicationDiscoveryListener applicationDiscoveryListener() {
ApplicationDiscoveryListener listener = new ApplicationDiscoveryListener(discoveryClient,
registry);
......
......@@ -73,7 +73,7 @@ public class ApplicationDiscoveryListener {
}
}
public void discover() {
protected void discover() {
for (String serviceId : discoveryClient.getServices()) {
for (ServiceInstance instance : discoveryClient.getInstances(serviceId)) {
registry.register(convert(instance));
......@@ -81,7 +81,7 @@ public class ApplicationDiscoveryListener {
}
}
private Application convert(ServiceInstance instance) {
protected Application convert(ServiceInstance instance) {
String serviceUrl = append(instance.getUri().toString(), serviceContextPath);
String managementUrl = append(instance.getUri().toString(), managementContextPath);
String healthUrl = append(managementUrl, healthEndpoint);
......@@ -102,7 +102,7 @@ public class ApplicationDiscoveryListener {
this.healthEndpoint = healthEndpoint;
}
private String append(String uri, String path) {
protected final String append(String uri, String path) {
String baseUri = uri.replaceFirst("/+$", "");
if (StringUtils.isEmpty(path)) {
return baseUri;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment