Makes app.internal configurable.
This commit is contained in:
@@ -42,7 +42,7 @@ public class CloudFoundryDiscoveryClientConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnBean(CloudFoundryDiscoveryClient.class)
|
||||
public CloudFoundryHeartbeatSender cloudFoundryHeartbeatSender(
|
||||
CloudFoundryDiscoveryClient client) {
|
||||
CloudFoundryDiscoveryClient client) {
|
||||
return new CloudFoundryHeartbeatSender(client);
|
||||
}
|
||||
|
||||
@@ -67,21 +67,22 @@ public class CloudFoundryDiscoveryClientConfiguration {
|
||||
@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-container-ip", havingValue = "true")
|
||||
@ConditionalOnMissingBean(DiscoveryClient.class)
|
||||
public SimpleDnsBasedDiscoveryClient discoveryClient(
|
||||
ObjectProvider<ServiceIdToHostnameConverter> provider) {
|
||||
ObjectProvider<ServiceIdToHostnameConverter> provider,
|
||||
CloudFoundryDiscoveryProperties properties) {
|
||||
ServiceIdToHostnameConverter converter = provider.getIfAvailable();
|
||||
return converter == null ? new SimpleDnsBasedDiscoveryClient()
|
||||
: new SimpleDnsBasedDiscoveryClient(converter);
|
||||
return converter == null ? new SimpleDnsBasedDiscoveryClient(properties)
|
||||
: new SimpleDnsBasedDiscoveryClient(properties, converter);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-container-ip", havingValue = "false", matchIfMissing = true)
|
||||
@ConditionalOnMissingBean(DiscoveryClient.class)
|
||||
public CloudFoundryAppServiceDiscoveryClient cloudFoundryDiscoveryClient(CloudFoundryOperations cf,
|
||||
CloudFoundryService svc,
|
||||
CloudFoundryDiscoveryProperties cloudFoundryDiscoveryProperties) {
|
||||
return new CloudFoundryAppServiceDiscoveryClient(cf, svc,
|
||||
cloudFoundryDiscoveryProperties);
|
||||
public CloudFoundryAppServiceDiscoveryClient cloudFoundryDiscoveryClient(
|
||||
CloudFoundryOperations cf, CloudFoundryService svc,
|
||||
CloudFoundryDiscoveryProperties properties) {
|
||||
return new CloudFoundryAppServiceDiscoveryClient(cf, svc, properties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.cloudfoundry.discovery;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
|
||||
/**
|
||||
* @author Josh Long
|
||||
@@ -46,6 +47,11 @@ public class CloudFoundryDiscoveryProperties {
|
||||
*/
|
||||
private int order = 0;
|
||||
|
||||
/**
|
||||
* Default internal domain when configured to use Native DNS service discovery.
|
||||
*/
|
||||
private String internalDomain = "apps.internal";
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
@@ -78,12 +84,25 @@ public class CloudFoundryDiscoveryProperties {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public String getInternalDomain() {
|
||||
return this.internalDomain;
|
||||
}
|
||||
|
||||
public void setInternalDomain(String internalDomain) {
|
||||
this.internalDomain = internalDomain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CloudFoundryDiscoveryProperties{" + "enabled=" + this.enabled
|
||||
+ ", heartbeatFrequency=" + this.heartbeatFrequency
|
||||
+ ", defaultServerPort=" + this.defaultServerPort + ", order="
|
||||
+ this.order + '}';
|
||||
// @formatter:off
|
||||
return new ToStringCreator(this)
|
||||
.append("enabled", enabled)
|
||||
.append("heartbeatFrequency", heartbeatFrequency)
|
||||
.append("defaultServerPort", defaultServerPort)
|
||||
.append("order", order)
|
||||
.append("internalDomain", internalDomain)
|
||||
.toString();
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,27 +34,24 @@ import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
* Discovery.
|
||||
*
|
||||
* @author Toshiaki Maki
|
||||
*
|
||||
* @see <a href=
|
||||
* "https://www.cloudfoundry.org/blog/polyglot-service-discovery-container-networking-cloud-foundry/">Polyglot
|
||||
* Service Discovery for Container Networking in Cloud Foundry</a>
|
||||
*/
|
||||
public class SimpleDnsBasedDiscoveryClient implements DiscoveryClient {
|
||||
public static final String INTERNAL_DOMAIN = "apps.internal";
|
||||
private final Logger log = LoggerFactory
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(SimpleDnsBasedDiscoveryClient.class);
|
||||
|
||||
private final ServiceIdToHostnameConverter serviceIdToHostnameConverter;
|
||||
|
||||
private static final ServiceIdToHostnameConverter DEFAULT_CONVERTER = serviceId -> serviceId
|
||||
+ "." + INTERNAL_DOMAIN;
|
||||
|
||||
public SimpleDnsBasedDiscoveryClient(
|
||||
public SimpleDnsBasedDiscoveryClient(CloudFoundryDiscoveryProperties properties,
|
||||
ServiceIdToHostnameConverter serviceIdToHostnameConverter) {
|
||||
this.serviceIdToHostnameConverter = serviceIdToHostnameConverter;
|
||||
}
|
||||
|
||||
public SimpleDnsBasedDiscoveryClient() {
|
||||
this(DEFAULT_CONVERTER);
|
||||
public SimpleDnsBasedDiscoveryClient(CloudFoundryDiscoveryProperties properties) {
|
||||
this(properties, serviceId -> serviceId + "." + properties.getInternalDomain());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,6 +88,9 @@ public class SimpleDnsBasedDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ServiceIdToHostnameConverter {
|
||||
|
||||
String toHostname(String serviceId);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user