Class ConsulBundle<C extends io.dropwizard.Configuration>

  • Type Parameters:
    C - The configuration class for your Dropwizard Application.
    All Implemented Interfaces:
    io.dropwizard.ConfiguredBundle<C>, ConsulConfiguration<C>

    public abstract class ConsulBundle<C extends io.dropwizard.Configuration>
    extends Object
    implements io.dropwizard.ConfiguredBundle<C>, ConsulConfiguration<C>
    Replace variables with values from Consul KV. By default, this only works with a Consul agent running on localhost:8500 (the default) as there's no way to configure Consul in the initialize methods. You may override getConsulAgentHost() and getConsulAgentPort() to provide other defaults.
    • Constructor Detail

      • ConsulBundle

        public ConsulBundle​(String name)
        Constructor
        Parameters:
        name - Service Name
      • ConsulBundle

        public ConsulBundle​(String name,
                            boolean strict)
        Parameters:
        name - Service Name
        strict - If true, the application fails fast if a key cannot be found in Consul KV
      • ConsulBundle

        public ConsulBundle​(String name,
                            boolean strict,
                            boolean substitutionInVariables)
        Parameters:
        name - Service Name
        strict - If true, the application fails fast if a key cannot be found in Consul KV
        substitutionInVariables - If true, substitution will be done within variable names.
    • Method Detail

      • initialize

        public void initialize​(io.dropwizard.setup.Bootstrap<?> bootstrap)
        Specified by:
        initialize in interface io.dropwizard.ConfiguredBundle<C extends io.dropwizard.Configuration>
      • run

        public void run​(C configuration,
                        io.dropwizard.setup.Environment environment)
        Specified by:
        run in interface io.dropwizard.ConfiguredBundle<C extends io.dropwizard.Configuration>
      • runEnabled

        protected void runEnabled​(ConsulFactory consulFactory,
                                  io.dropwizard.setup.Environment environment)
      • setupEnvironment

        protected void setupEnvironment​(ConsulFactory consulFactory,
                                        io.dropwizard.setup.Environment environment)
      • getConsulAgentHost

        public String getConsulAgentHost()
        Override as necessary to provide an alternative Consul Agent Host. This is only required if using Consul KV for configuration variable substitution.
        Returns:
        By default, "localhost"
      • getConsulAgentPort

        public int getConsulAgentPort()
        Override as necessary to provide an alternative Consul Agent Port. This is only required if using Consul KV for configuration variable substitution.
        Returns:
        By default, 8500
      • getConsulAclToken

        public Optional<String> getConsulAclToken()
        Override as necessary to provide an alternative ACL Token. This is only required if using Consul KV for configuration variable substitution.
        Returns:
        By default, empty string (no ACL support)
      • didAttemptInitialize

        public boolean didAttemptInitialize()
        Checks whether Dropwizard has attempted to initialize this bundle.
        Returns:
        true if Dropwizard called initialize(Bootstrap), false otherwise
      • didInitializeSucceed

        public boolean didInitializeSucceed()
        Check whether this bundle has been successfully initialized.

        Note that if didAttemptInitialize() returns false, then this method will always return false (it cannot report success if initialization has not been attempted).

        Returns:
        true if initialize(Bootstrap) executed without error, false otherwise