Class ConsulBundle<C extends io.dropwizard.core.Configuration>
java.lang.Object
org.kiwiproject.dropwizard.consul.ConsulBundle<C>
- Type Parameters:
C
- The configuration class for your Dropwizard Application.
- All Implemented Interfaces:
io.dropwizard.core.ConfiguredBundle<C>
,ConsulConfiguration<C>
public abstract class ConsulBundle<C extends io.dropwizard.core.Configuration>
extends Object
implements io.dropwizard.core.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 Summary
ConstructorDescriptionConsulBundle
(String name) ConstructorConsulBundle
(String name, boolean strict) ConsulBundle
(String name, boolean strict, boolean substitutionInVariables) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks whether Dropwizard has attempted to initialize this bundle.boolean
Check whether this bundle has been successfully initialized.Override as necessary to provide an alternative ACL Token.Override as necessary to provide an alternative Consul Agent Host.int
Override as necessary to provide an alternative Consul Agent Port.void
initialize
(io.dropwizard.core.setup.Bootstrap<?> bootstrap) void
protected void
runEnabled
(ConsulFactory consulFactory, io.dropwizard.core.setup.Environment environment) protected void
setupEnvironment
(ConsulFactory consulFactory, io.dropwizard.core.setup.Environment environment) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.kiwiproject.dropwizard.consul.ConsulConfiguration
getConsulFactory
-
Constructor Details
-
ConsulBundle
Constructor- Parameters:
name
- Service Name
-
ConsulBundle
- Parameters:
name
- Service Namestrict
- If true, the application fails fast if a key cannot be found in Consul KV
-
ConsulBundle
- Parameters:
name
- Service Namestrict
- If true, the application fails fast if a key cannot be found in Consul KVsubstitutionInVariables
- If true, substitution will be done within variable names.
-
-
Method Details
-
initialize
public void initialize(io.dropwizard.core.setup.Bootstrap<?> bootstrap) - Specified by:
initialize
in interfaceio.dropwizard.core.ConfiguredBundle<C extends io.dropwizard.core.Configuration>
-
run
- Specified by:
run
in interfaceio.dropwizard.core.ConfiguredBundle<C extends io.dropwizard.core.Configuration>
-
runEnabled
protected void runEnabled(ConsulFactory consulFactory, io.dropwizard.core.setup.Environment environment) -
setupEnvironment
protected void setupEnvironment(ConsulFactory consulFactory, io.dropwizard.core.setup.Environment environment) -
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
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 an error, false otherwise
-