Skip to content

Getting started

Plain Java

Most applications start at layer 1, where your code works with your own domain events. In code, it looks like this:

// Your domain is a pure function from past events to new events, with no dependency on Occurrent.
List<GameEvent> handle(List<GameEvent> history, GameCommand command) { ... }
// Occurrent's application service loads the stream, runs your function, and appends the new events under optimistic concurrency.
ApplicationService<GameEvent> applicationService = new GenericApplicationService<>(eventStore, cloudEventConverter);
applicationService.execute(gameId, history -> handle(history, command));

These are the steps to get there:

  1. Pick an event store. Use MongoDB in production and the in-memory event store for tests and experiments. See Choosing an EventStore.
  2. Pick a CloudEventConverter. It maps your domain events to CloudEvents and back. The Jackson converter is a good default. Configure how it names event types before you go to production, since the type ends up in every stored event.
  3. Create an ApplicationService and call your domain functions through it, as in the example above.
  4. React to events. Pick a subscription model for your store, and a checkpoint storage if a subscriber should continue where it left off after a restart. Then use Subscriptions, projections or sagas to work with domain events.
  5. Query events with DomainEventQueries when you need to.

With Spring Boot and MongoDB, the Spring Boot starter sets all of this up for you, and gives you ApplicationService, Subscriptions and DomainEventQueries beans to inject. There’s also a reactive starter.

You can always drop down to layer 0 and use the event store and subscriptions with CloudEvents directly. It’s worth reading about CloudEvents and their specification either way, because that is how your events are stored.