is a lightweight container friendly library which utilises event sourcing pattern to write loosely coupled, scalable microservices in Java. Please note that Event Sourcing and Event driven architecture are two different things. If you haven't heard about Event Sourcing I suggest you to visit Chris Richardson's page and read about it.
Initial project consists of five libraries.
- Common : A shared library which contains Annotations, Interfaces etc.
- Core : The core library which contains core components such as AggregateService, EventHandlingContext etc.
- Spring auto-configuration for Core Module
- JDBCEventStore: JDBC implementation of EventStore.
- Spring auto-configuration for JDBCEventStore module
The following sequence diagram shows how a request is handled.
The EventStore component is an adapter which can be implemented in different technologies and techniques (polling, change data capture etc). The EventStore is responsible for publishing and consuming events in sequential order. The MVP will contain JDBC implementation of EventStore which uses Postgres database.
Separate modules will be developed to work with different frameworks such as SpringBoot, Micronaut, Quarkus etc. The MVP will only contain SpringBoot auto-configuration.
@EventSourcingEnabled, @Event, @AggregateEventHandler and @EventHandler annotations is used to make the configuration easier.
An example SpringBootApplication configuration:
@SpringBootApplication
@EventSourcingEnabled
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}Event example:
@Event(name="orderservice.order-created")
public class OrderCreatedEvent {
}Aggregate example:
public class Order {
@AggregateEventHandler
public void handleOrderCreated(OrderCreatedEvent event) {
}
public List<Envelope<Object>> createOrder(Order order) {
return Collections.singletonList(new Envelope(new Metadata(), new OrderCreatedEvent(product)));
}
}EventListener example:
public class OrderEventListener {
@EventHandler
public void handleOrderCreated(OrderCreatedEvent event) {
repository.save(event.getOrder());
}
}To handle event along with metadata information you can use Envelope as the argument.
public class OrderEventListener {
@EventHandler
public void handleOrderCreated(Envelope<OrderCreatedEvent> event) {
repository.save(event.getOrder());
}
}JDBC eventstore stores events in Postgres by default. To deliver messages to event listeners, the delivery queue will be consumed regularly by workers. Worker parameters will be set in application.yaml file.
Parameters: Worker count, polling interval, polling item count, max retry count, retry interval.
Snapshots, Event Replay won't be in the MVP.
Navigate to the folder 'inventory' and run './run.sh' command in the terminal. Example requests are in the file 'request.http'.
