Class StorkConfigUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ServiceConfigurationaddRegistrarTypeIfAbsent(String serviceRegistrarType, ServiceConfiguration serviceConfiguration, String healthCheckUrl) Returns a copy of the givenServiceConfigurationwith the registrar type and optional health check URL added if the registrar type is not already set.static ServiceConfigurationbuildDefaultRegistrarConfiguration(String serviceRegistrarType, String healthCheckPath) Builds a defaultServiceConfigurationfor a Quarkus application when no explicit service registrar configuration is defined by the developer.static InetAddressAttempts to detect the first valid non-loopback IPv4 address of the host machine.static StringgetOrDefaultHost(Map<String, String> parameters, org.eclipse.microprofile.config.Config quarkusConfig) Resolves the host (IP address or hostname) to use for service registration.static intgetOrDefaultPort(Map<String, String> parameters, org.eclipse.microprofile.config.Config quarkusConfig) Resolves the port to use for service registration.static voidstatic List<io.smallrye.stork.api.config.ServiceConfig> toStorkServiceConfig(StorkConfiguration storkConfiguration)
-
Constructor Details
-
StorkConfigUtil
public StorkConfigUtil()
-
-
Method Details
-
toStorkServiceConfig
public static List<io.smallrye.stork.api.config.ServiceConfig> toStorkServiceConfig(StorkConfiguration storkConfiguration) -
buildDefaultRegistrarConfiguration
public static ServiceConfiguration buildDefaultRegistrarConfiguration(String serviceRegistrarType, String healthCheckPath) Builds a defaultServiceConfigurationfor a Quarkus application when no explicit service registrar configuration is defined by the developer.This method generates a minimal configuration with the provided registrar type and optionally includes a fully resolved health check URL. It retrieves default host and port values from the current Quarkus configuration if needed to complete the health check URL.
- Parameters:
serviceRegistrarType- the type of the registrar (e.g., "consul", "eureka"); must not be blankhealthCheckPath- the relative path to the health check endpoint (e.g.,/q/health/live); if provided, a full URL will be constructed using default host and port- Returns:
- a
ServiceConfigurationpre-filled with the type and optional health check URL - Throws:
IllegalArgumentException- ifserviceRegistrarTypeis null or blank
-
addRegistrarTypeIfAbsent
public static ServiceConfiguration addRegistrarTypeIfAbsent(String serviceRegistrarType, ServiceConfiguration serviceConfiguration, String healthCheckUrl) Returns a copy of the givenServiceConfigurationwith the registrar type and optional health check URL added if the registrar type is not already set.If the registrar is already present, its configuration is reused and only the missing health check URL may be appended. The registrar is marked as enabled by default unless specified otherwise.
- Parameters:
serviceRegistrarType- the registrar type to set if missing (e.g., "consul"); must not be blankserviceConfiguration- the existing service configuration to updatehealthCheckUrl- optional full health check URL to add to the parameters- Returns:
- an updated
ServiceConfigurationwith type and health check URL as needed - Throws:
IllegalArgumentException- ifserviceRegistrarTypeis null or blank
-
getOrDefaultHost
public static String getOrDefaultHost(Map<String, String> parameters, org.eclipse.microprofile.config.Config quarkusConfig) Resolves the host (IP address or hostname) to use for service registration.The method follows the following resolution strategy:
- If
parameterscontains a customip-address, it is returned. - Otherwise, in dev/test mode,
localhostis used as fallback. - In other modes,
0.0.0.0is used unless overridden byquarkus.http.host. - Finally, if no configuration is present, the method attempts to detect a valid local IP address.
- Parameters:
parameters- a map of registrar parameters that may includeip-addressquarkusConfig- the active QuarkusConfiginstance- Returns:
- the resolved host to use for registration
- If
-
getOrDefaultPort
public static int getOrDefaultPort(Map<String, String> parameters, org.eclipse.microprofile.config.Config quarkusConfig) Resolves the port to use for service registration.Priority order:
- If
parametersincludes aport, it is used. - Else, the value from
quarkus.http.portis used, if present. - Otherwise, defaults to
8080.
- Parameters:
parameters- a map of registrar parameters that may includeportquarkusConfig- the active QuarkusConfiginstance- Returns:
- the resolved port as an integer
- If
-
detectAddress
Attempts to detect the first valid non-loopback IPv4 address of the host machine.This is used when no explicit IP address is configured. The method iterates over all available network interfaces, filtering out loopback and down interfaces.
If detection fails, it falls back to
InetAddress.getLocalHost().- Returns:
- the detected
InetAddress, ornullif none found
-
requireRegistrarTypeNotBlank
-