Examples
The example folder in the repository has runnable, tested applications that put the concepts on this page together. The table below points to the most instructive ones and highlights which Occurrent features each demonstrates. Every link is pinned to the 0.34.0 release.
| Example | What it shows | Occurrent features |
|---|---|---|
| Number guessing game | A guess-the-secret-number game in plain Java, wired up two ways: the native MongoDB driver and Spring Boot (blocking). | GenericApplicationService, native and Spring (blocking) MongoDB event stores, subscription-based read models, side-effects (policies), integration events, CloudEventConverter |
| Word guessing game | A hangman-style word game as a full feature-sliced CQRS app on Spring Boot, in both a classic stream version and a DCB version. | Blocking subscriptions, subscription-driven side-effects (reveal hint, award points, email winner), MongoDB read models with the Query DSL, CloudEventConverter, DCB, jqwik property tests |
| Rock paper scissors | The same game modelled several ways (pragmatic, single-round and multi-round Decider), plus a Spring Boot web app that plays it. | Decider DSL, combining and multi-round deciders, Spring Boot starter (@EnableOccurrent), CQRS gameplay and views, blocking subscriptions |
| Uno | The Uno card game as a pure event-sourced model, run against the native MongoDB driver and Spring. | Event-sourced model, native and Spring MongoDB event stores, GenericApplicationService, command composition, NativeMongoSubscriptionModel |
| Mastermind | The Mastermind board game modelled with the Decider pattern, playable against the computer. | Decider DSL, in-memory event store, ApplicationService |
| Course enrollment | Enrolling a student holds a course-capacity rule and a per-student limit at once, across two entities, using DCB. | DCB, blocking DcbApplicationService, dcbDecider DSL, Spring Boot starter auto-configuration, conditional append with retry |
| Hotel booking | The reactive twin of course enrollment: no double-booking a room, a per-guest active-booking limit, and a live SSE activity feed. | Reactive DCB, reactive DcbApplicationService, DCB subscription DSL (SSE feed), reactive Spring Boot starter, cross-boundary deciders |
| Appointment scheduling | A clinic scheduler that books a clinician, patient and time slot under one consistency boundary, in plain Java with no Spring. | DCB on the native MongoDB store, plain Java Deciders with a hand-built DcbCriteria, @DcbTag annotation tags (AnnotationTagGenerator), Javalin and j2html web |
| DCB patterns catalog | Five self-contained vignettes covering the dcb.events patterns the other examples do not show: unique username with a retention period, idempotency, a price change grace period, a consume-once opt-in token, and a gapless invoice number. Kotlin, no Spring, no Docker. | DCB, DcbDecider, GenericDcbApplicationService, in-memory DCB event store, uniqueness and idempotency as a scoped append condition, DcbReadOptions.fromBeginning().backwards().limit(1) |
| Projection DSL | Four vignettes on the Projection DSL, in Java and Kotlin, stream and DCB. Each projection is run two ways, pushed through a subscription into a stored read model and run over a query on demand, and the two are asserted to agree. | Projection, DcbProjection, the Java handler builder and the Kotlin projection { } DSL, MaterializedView, an explicit Filter selecting on subject, tag-scoped single-instance read models, in-memory event store and subscription model |
| Global position catch-up | The global position assigned to every event, and rebuilding a projection by replaying across streams in write order. | Global position, catch-up projections, DomainEventQueries.readInPositionOrder, in-memory event store, withoutStreamPosition() opt-out |
| Subscription-based projections | Building a MongoDB read model by subscribing to the event stream. | Blocking subscriptions, MongoDB read models, CloudEventConverter |
| Transactional projection (blocking) | Updating a projection in the same MongoDB transaction as the event append. | Blocking Spring MongoDB event store, same-transaction projections |
| Transactional projection (reactive) | The reactive version of the transactional projection. | Reactive Spring MongoDB event store, same-transaction projections on Project Reactor |
| Ad-hoc event store queries | Answering a query (most workouts completed) by querying the event store directly, with no separate read model. | EventStore queries, ad-hoc querying, Spring MongoDB |
| Order fulfillment saga | One order-fulfillment process written twice, with the machine-core Saga.builder(...) in Java and with the Kotlin flow saga { } block, both run through SagaRunner. Placing an order reserves payment and arms a timeout, a reservation ships the order, and a payment failure or the timeout firing cancels it. In-memory, no Docker. | Saga, the core and flow saga DSLs, SagaRunner, per-instance state and timers, CommandDispatcher both as a plain ApplicationService lambda and through the CommandDispatchers.decider(...) adapter |
| Closing the books | An account ledger using both snapshot styles: everyNEvents to keep a long-lived stream’s replay bounded, and whenTerminal to snapshot the closing balance when the books close. The closing balance carries into the next period as an event, so the closed period’s detailed events can be archived without losing money. In-memory, no Docker. | SnapshotDeciderApplicationService, SnapshotPolicy (everyNEvents, whenTerminal), schemaVersion falling back to a full replay, EventStoreOperations.deleteEventStream |
| Forward to Spring events | Forwarding CloudEvents from a MongoDB subscription to Spring ApplicationEvents. | Blocking subscriptions, Spring ApplicationEventPublisher integration |
