Configuring the Spring application context

Once you have written your services and event handlers you must configure the Spring application context to instantiate them and wire them together.

Define Spring beans for your services and event handlers

You must define Spring beans for your services and event handlers. As always, you can either do this explicitly using @Bean definitions or you can use component scanning.

Define Spring Beans for your snapshot strategies

If you are using snapshot strategies they must be defined as Spring Beans. For example,

@Bean
public AccountSnapshotStrategy accountSnapshotStrategy() {
  return new AccountSnapshotStrategy();
}

Enabling the high-level event handler API

If your code uses the high-level event handler API then you must annotate your @Configuration class with @EnableEventHandlers:

@Configuration
@EnableEventHandlers
class MyConfigurationClass {
  ...
}

Choosing the Event Store implementation

You must @Import into your Spring ApplicationContext an @Configuration class for an event store client implementation. There are the following options:

  • @Import(EventuateDriverConfiguration.class) - used in your production code and perhaps your test code. Depending on which libraries are on the class path, it imports the configuration for the Eventuate HTTP/STOMP client or the Eventuate Local client.

  • @Import(EmbeddedTestAggregateStoreConfiguration.class) - imports the configuration for the embedded test Event Store. This is useful for tests.

Externalized configuration for the Event Store Client

The Eventuate Client uses the Spring Boot Externalized configuration mechanism.

You must specify the following properties:

  • spring.datasource.url
  • spring.datasource.username
  • spring.datasource.password
  • eventuatelocal.kafka.bootstrap.servers - Apache Kafka servers, e.g. kafkaserver:9092

Stay in touch
Copyright © 2021 Eventuate, Inc • All rights reserved.