Commit 1eec10c5 by Johannes Edmeier

Make ApplicationDiscoveryListener customizable

parent b107544a
...@@ -18,8 +18,9 @@ package de.codecentric.boot.admin.config; ...@@ -18,8 +18,9 @@ package de.codecentric.boot.admin.config;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; 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.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration; import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -29,7 +30,7 @@ import de.codecentric.boot.admin.discovery.ApplicationDiscoveryListener; ...@@ -29,7 +30,7 @@ import de.codecentric.boot.admin.discovery.ApplicationDiscoveryListener;
import de.codecentric.boot.admin.registry.ApplicationRegistry; import de.codecentric.boot.admin.registry.ApplicationRegistry;
@Configuration @Configuration
@ConditionalOnClass({ DiscoveryClient.class }) @ConditionalOnSingleCandidate(DiscoveryClient.class)
@ConditionalOnProperty(prefix = "spring.boot.admin.discovery", name = "enabled", matchIfMissing = true) @ConditionalOnProperty(prefix = "spring.boot.admin.discovery", name = "enabled", matchIfMissing = true)
@AutoConfigureAfter({ NoopDiscoveryClientAutoConfiguration.class }) @AutoConfigureAfter({ NoopDiscoveryClientAutoConfiguration.class })
public class DiscoveryClientConfiguration { public class DiscoveryClientConfiguration {
...@@ -44,6 +45,7 @@ public class DiscoveryClientConfiguration { ...@@ -44,6 +45,7 @@ public class DiscoveryClientConfiguration {
private ApplicationRegistry registry; private ApplicationRegistry registry;
@Bean @Bean
@ConditionalOnMissingBean
public ApplicationDiscoveryListener applicationDiscoveryListener() { public ApplicationDiscoveryListener applicationDiscoveryListener() {
ApplicationDiscoveryListener listener = new ApplicationDiscoveryListener(discoveryClient, ApplicationDiscoveryListener listener = new ApplicationDiscoveryListener(discoveryClient,
registry); registry);
......
...@@ -73,7 +73,7 @@ public class ApplicationDiscoveryListener { ...@@ -73,7 +73,7 @@ public class ApplicationDiscoveryListener {
} }
} }
public void discover() { protected void discover() {
for (String serviceId : discoveryClient.getServices()) { for (String serviceId : discoveryClient.getServices()) {
for (ServiceInstance instance : discoveryClient.getInstances(serviceId)) { for (ServiceInstance instance : discoveryClient.getInstances(serviceId)) {
registry.register(convert(instance)); registry.register(convert(instance));
...@@ -81,7 +81,7 @@ public class ApplicationDiscoveryListener { ...@@ -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 serviceUrl = append(instance.getUri().toString(), serviceContextPath);
String managementUrl = append(instance.getUri().toString(), managementContextPath); String managementUrl = append(instance.getUri().toString(), managementContextPath);
String healthUrl = append(managementUrl, healthEndpoint); String healthUrl = append(managementUrl, healthEndpoint);
...@@ -102,7 +102,7 @@ public class ApplicationDiscoveryListener { ...@@ -102,7 +102,7 @@ public class ApplicationDiscoveryListener {
this.healthEndpoint = healthEndpoint; this.healthEndpoint = healthEndpoint;
} }
private String append(String uri, String path) { protected final String append(String uri, String path) {
String baseUri = uri.replaceFirst("/+$", ""); String baseUri = uri.replaceFirst("/+$", "");
if (StringUtils.isEmpty(path)) { if (StringUtils.isEmpty(path)) {
return baseUri; 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