Class StorkConfigUtil

java.lang.Object
io.quarkus.stork.StorkConfigUtil

public class StorkConfigUtil extends Object
  • 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 default ServiceConfiguration for 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 blank
      healthCheckPath - 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 ServiceConfiguration pre-filled with the type and optional health check URL
      Throws:
      IllegalArgumentException - if serviceRegistrarType is null or blank
    • addRegistrarTypeIfAbsent

      public static ServiceConfiguration addRegistrarTypeIfAbsent(String serviceRegistrarType, ServiceConfiguration serviceConfiguration, String healthCheckUrl)
      Returns a copy of the given ServiceConfiguration with 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 blank
      serviceConfiguration - the existing service configuration to update
      healthCheckUrl - optional full health check URL to add to the parameters
      Returns:
      an updated ServiceConfiguration with type and health check URL as needed
      Throws:
      IllegalArgumentException - if serviceRegistrarType is 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 parameters contains a custom ip-address, it is returned.
      • Otherwise, in dev/test mode, localhost is used as fallback.
      • In other modes, 0.0.0.0 is used unless overridden by quarkus.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 include ip-address
      quarkusConfig - the active Quarkus Config instance
      Returns:
      the resolved host to use for registration
    • 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:

      1. If parameters includes a port, it is used.
      2. Else, the value from quarkus.http.port is used, if present.
      3. Otherwise, defaults to 8080.
      Parameters:
      parameters - a map of registrar parameters that may include port
      quarkusConfig - the active Quarkus Config instance
      Returns:
      the resolved port as an integer
    • detectAddress

      public static InetAddress 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, or null if none found
    • requireRegistrarTypeNotBlank

      public static void requireRegistrarTypeNotBlank(String type)