Class ConsulBundle<C extends io.dropwizard.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.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 overridegetConsulAgentHost()
andgetConsulAgentPort()
to provide other defaults.
-
-
Constructor Summary
Constructors Constructor Description ConsulBundle(String name)
ConstructorConsulBundle(String name, boolean strict)
ConsulBundle(String name, boolean strict, boolean substitutionInVariables)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
didAttemptInitialize()
Checks whether Dropwizard has attempted to initialize this bundle.boolean
didInitializeSucceed()
Check whether this bundle has been successfully initialized.Optional<String>
getConsulAclToken()
Override as necessary to provide an alternative ACL Token.String
getConsulAgentHost()
Override as necessary to provide an alternative Consul Agent Host.int
getConsulAgentPort()
Override as necessary to provide an alternative Consul Agent Port.void
initialize(io.dropwizard.setup.Bootstrap<?> bootstrap)
void
run(C configuration, io.dropwizard.setup.Environment environment)
protected void
runEnabled(ConsulFactory consulFactory, io.dropwizard.setup.Environment environment)
protected void
setupEnvironment(ConsulFactory consulFactory, io.dropwizard.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 Detail
-
ConsulBundle
public ConsulBundle(String name)
Constructor- Parameters:
name
- Service Name
-
ConsulBundle
public ConsulBundle(String name, boolean strict)
- Parameters:
name
- Service Namestrict
- 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 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 Detail
-
initialize
public void initialize(io.dropwizard.setup.Bootstrap<?> bootstrap)
- Specified by:
initialize
in interfaceio.dropwizard.ConfiguredBundle<C extends io.dropwizard.Configuration>
-
run
public void run(C configuration, io.dropwizard.setup.Environment environment)
- Specified by:
run
in interfaceio.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
-
-