Class HekateConfigurer
- java.lang.Object
-
- io.hekate.spring.boot.HekateConfigurer
-
@Configuration @ConditionalOnMissingBean(Hekate.class) @ConditionalOnProperty(name="hekate.enable", havingValue="true", matchIfMissing=true) public class HekateConfigurer extends Object
« start hereAuto-configuration forHekate
instances.Overview
This class provides support for automatic configuration and bootstrapping of
Hekate
instances via Spring Boot. In order to enable this auto-configuration the 'hekate-spring-boot' dependency must be added to a Spring Boot-enabled project (see 'Module dependency' section below) and@EnableHekate
annotation must be placed on application class (see Usage example section below).Module Dependency
Spring Boot integration is provided by the 'hekate-spring-boot' module and can be imported into the project dependency management system as in the example below:
<dependency> <groupId>io.hekate</groupId> <artifactId>hekate-spring-boot</artifactId> <version>4.0.0</version> </dependency>
compile group: 'io.hekate', name: 'hekate-spring-boot', version: '4.0.0'
<dependency org="io.hekate" name="hekate-spring-boot" rev="4.0.0"/>
Usage Example
The code example below shows how
Hekate
auto-configuration can be used in a Spring Boot-enabled applications.First lets define some component that depends on
Hekate
instance.public class MyComponent { private final Hekate hekate; public MyComponent(Hekate hekate) { this.hekate = hekate; } @PostConstruct public void doSomething() { System.out.println("Hekate node: " + hekate.localNode()); } }
@EnableHekate
annotation)...@EnableHekate // <-- Important!!! @SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } @Bean public MyComponent myComponent(Hekate hekate) { return new MyComponent(hekate); } }
Hekate
instance doesn't require any manual construction.Registering and Configuring Services
This class automatically registers all application-provided
Bean
s ofServiceFactory
type into the auto-configuredHekate
instance.Additionally each service has its own auto-configuration class that simplifies configuration and registration of services and components. Please see the documentation of the following classes:
HekateClusterServiceConfigurer
HekateMessagingServiceConfigurer
HekateNetworkServiceConfigurer
HekateLockServiceConfigurer
HekateCoordinationServiceConfigurer
HekateElectionServiceConfigurer
Configuration Options
The following application properties can be used to configure the constructed
Hekate
instance:'hekate.node-name'
'hekate.roles'
'hekate.properties'
HekateBootstrap.setConfigReport(boolean)
'hekate.config-report'}'hekate.on-fatal-error'
Deferred Cluster Joining
It is possible to control the timing of when
Hekate
node will start joining the cluster by specifying the following properties:'hekate.deferred-join'
- if set tofalse
(default value) then joining will happen synchronously during the Spring Application context initialization'hekate.deferred-join'
- if set totrue
then joining will be deferred until the Spring Application context gets fully initialized (signalled byApplicationReadyEvent
).
Furthermore it is also possible to completely disable joining to the cluster by setting the
'hekate.deferred-join-condition'
property value to'manual'
. In such case it is up to the application logic to decide on when to call theHekate.join()
method in order to start joining the cluster. Alternative value of this property is'app-ready'
which will fall back to the default behavior.
-
-
Constructor Summary
Constructors Constructor Description HekateConfigurer(Optional<List<PropertyProvider>> propertyProviders, Optional<List<ServiceFactory<?>>> services, Optional<List<Plugin>> plugins, Optional<List<Hekate.LifecycleListener>> listeners, Optional<io.micrometer.core.instrument.MeterRegistry> metrics, Optional<HekateFatalErrorPolicy> fatalErrorPolicy, Optional<CodecFactory<Object>> codec)
Constructs new instance with autowired dependencies.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CodecServiceBean
codecService()
ExportsCodecService
bean.HekateSpringBootstrap
hekate()
Constructs theHekate
factory bean.
-
-
-
Constructor Detail
-
HekateConfigurer
public HekateConfigurer(Optional<List<PropertyProvider>> propertyProviders, Optional<List<ServiceFactory<?>>> services, Optional<List<Plugin>> plugins, Optional<List<Hekate.LifecycleListener>> listeners, Optional<io.micrometer.core.instrument.MeterRegistry> metrics, Optional<HekateFatalErrorPolicy> fatalErrorPolicy, @Qualifier("default") Optional<CodecFactory<Object>> codec)
Constructs new instance with autowired dependencies.- Parameters:
propertyProviders
- AllPropertyProvider
s found in the application context.services
- AllServiceFactory
s found in the application context.plugins
- AllPlugin
s found in the application context.listeners
- AllHekate.LifecycleListener
s found in the application context.metrics
- Metrics registry.codec
- Default codec factory.fatalErrorPolicy
- Fatal error handling policy.
-
-
Method Detail
-
codecService
@Bean public CodecServiceBean codecService()
ExportsCodecService
bean.- Returns:
CodecService
bean.
-
hekate
@Bean @ConfigurationProperties(prefix="hekate") public HekateSpringBootstrap hekate()
Constructs theHekate
factory bean.- Returns:
Hekate
factory bean.
-
-