-
Notifications
You must be signed in to change notification settings - Fork 3k
Added support for dynamic discovery of Config Server instances #48121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
geoand
merged 1 commit into
quarkusio:main
from
poldinik:feature/47989-discovery-based-config-server-integration
Jul 4, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.../main/java/io/quarkus/spring/cloud/config/client/runtime/ConfigServerBaseUrlProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.quarkus.spring.cloud.config.client.runtime; | ||
|
||
import java.net.URI; | ||
|
||
public interface ConfigServerBaseUrlProvider { | ||
URI get(); | ||
} |
7 changes: 7 additions & 0 deletions
7
.../runtime/src/main/java/io/quarkus/spring/cloud/config/client/runtime/ConfigServerUrl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.quarkus.spring.cloud.config.client.runtime; | ||
|
||
import java.net.URI; | ||
|
||
public record ConfigServerUrl(URI baseURI, int port, String host, String completeURLString) { | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...java/io/quarkus/spring/cloud/config/client/runtime/DirectConfigServerBaseUrlProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.quarkus.spring.cloud.config.client.runtime; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.spring.cloud.config.client.runtime.util.UrlUtility; | ||
|
||
public class DirectConfigServerBaseUrlProvider implements ConfigServerBaseUrlProvider { | ||
|
||
private static final Logger log = Logger.getLogger(DirectConfigServerBaseUrlProvider.class); | ||
private final SpringCloudConfigClientConfig config; | ||
|
||
public DirectConfigServerBaseUrlProvider(SpringCloudConfigClientConfig config) { | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public URI get() { | ||
log.info("Getting config server URL with Direct ConfigServer BaseUrl"); | ||
String url = config.url(); | ||
validate(url); | ||
try { | ||
return UrlUtility.toURI(url); | ||
} catch (URISyntaxException e) { | ||
throw new IllegalArgumentException("Value: '" + config.url() | ||
+ "' of property 'quarkus.spring-cloud-config.url' is invalid", e); | ||
} | ||
} | ||
|
||
private void validate(String url) { | ||
if (null == url || url.isEmpty()) { | ||
throw new IllegalArgumentException( | ||
"The 'quarkus.spring-cloud-config.url' property cannot be empty"); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...a/io/quarkus/spring/cloud/config/client/runtime/DiscoveryConfigServerBaseUrlProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.quarkus.spring.cloud.config.client.runtime; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.spring.cloud.config.client.runtime.eureka.DiscoveryService; | ||
import io.quarkus.spring.cloud.config.client.runtime.util.UrlUtility; | ||
|
||
public class DiscoveryConfigServerBaseUrlProvider implements ConfigServerBaseUrlProvider { | ||
|
||
private static final Logger log = Logger.getLogger(DiscoveryConfigServerBaseUrlProvider.class); | ||
private final DiscoveryService discoveryService; | ||
private final SpringCloudConfigClientConfig config; | ||
|
||
public DiscoveryConfigServerBaseUrlProvider(DiscoveryService discoveryService, SpringCloudConfigClientConfig config) { | ||
this.discoveryService = discoveryService; | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public URI get() { | ||
log.info("Getting config server URL with Discovery ConfigServer"); | ||
try { | ||
return UrlUtility.toURI(discoveryService.discover(config)); | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
.../src/main/java/io/quarkus/spring/cloud/config/client/runtime/eureka/DiscoveryService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io.quarkus.spring.cloud.config.client.runtime.eureka; | ||
|
||
import static java.util.stream.Collectors.toMap; | ||
|
||
import java.util.Map; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.spring.cloud.config.client.runtime.SpringCloudConfigClientConfig; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class DiscoveryService { | ||
|
||
private static final Logger log = Logger.getLogger(DiscoveryService.class); | ||
private static final String DEFAULT_ZONE = "defaultZone"; | ||
|
||
private final EurekaClient eurekaClient; | ||
|
||
public DiscoveryService(EurekaClient eurekaClient) { | ||
this.eurekaClient = eurekaClient; | ||
} | ||
|
||
public String discover(SpringCloudConfigClientConfig config) { | ||
SpringCloudConfigClientConfig.DiscoveryConfig discoveryConfig = config.discovery().get(); | ||
validate(discoveryConfig); | ||
|
||
String serviceId = discoveryConfig.serviceId().get(); | ||
SpringCloudConfigClientConfig.DiscoveryConfig.EurekaConfig eurekaConfig = discoveryConfig.eurekaConfig().get(); | ||
String defaultServiceUrl = eurekaConfig.serviceUrl().get(DEFAULT_ZONE); | ||
|
||
Map<String, String> serviceUrlMap = eurekaConfig | ||
.serviceUrl() | ||
.entrySet() | ||
.stream().filter(entry -> !DEFAULT_ZONE.equals(entry.getKey())) | ||
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
|
||
log.debug("Attempting to discover Spring Cloud Config Server URL for service '" + serviceId | ||
+ "' using the following URLs: " + serviceUrlMap.values()); | ||
for (Map.Entry<String, String> entry : serviceUrlMap.entrySet()) { | ||
try { | ||
return getHomeUrl(entry.getValue(), serviceId); | ||
} catch (Exception e) { | ||
log.debug("Timed out while waiting for Spring Cloud Config Server URL for service '" + serviceId + "'", e); | ||
} | ||
} | ||
|
||
log.debug("Fallback Attempting to discover Spring Cloud Config Server URL for service '" + serviceId | ||
+ "' using the default URL: " + defaultServiceUrl); | ||
try { | ||
return getHomeUrl(defaultServiceUrl, serviceId); | ||
} catch (Exception e) { | ||
log.debug("Timed out while waiting for Spring Cloud Config Server URL for service '" + serviceId + "'", e); | ||
} | ||
|
||
throw new RuntimeException("Unable to discover Spring Cloud Config Server URL for service '" + serviceId + "'"); | ||
} | ||
|
||
private void validate(SpringCloudConfigClientConfig.DiscoveryConfig discoveryConfig) { | ||
if (discoveryConfig.eurekaConfig().isEmpty()) { | ||
throw new IllegalArgumentException("No Eureka configuration has been provided"); | ||
} | ||
if (discoveryConfig.eurekaConfig().get().serviceUrl().isEmpty()) { | ||
throw new IllegalArgumentException("No service URLs have been configured for service"); | ||
} | ||
if (discoveryConfig.serviceId().isEmpty()) { | ||
throw new IllegalArgumentException("No service ID has been configured for service"); | ||
} | ||
} | ||
|
||
private String getHomeUrl(String defaultServiceUrl, String serviceId) { | ||
JsonObject instance = eurekaClient.fetchInstances(defaultServiceUrl, serviceId); | ||
return instance.getString("homePageUrl"); | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should have another layer under
DiscoveryConfig
namedEurekaConfig
. The idea here being that in the future we might have some other way to do discovery (Stork for example).