Subscriptions
A subscription is a way to get notified when new events are written to an event store. Typically, a subscription will be used to create views from events (such as projections, sagas, snapshots etc) or create integration events that can be forwarded to another piece of infrastructure such as a message bus. There are two different kinds of APIs, the first one is a blocking API represented by the org.occurrent.subscription.api.blocking.SubscriptionModel interface (in the org.occurrent:occurrent-subscription-api-blocking module), and second one is a reactive API represented by the org.occurrent.subscription.api.reactor.FluxSubscriptionModel interface (in the org.occurrent:occurrent-subscription-api-reactor module).
The blocking API is callback based, which is fine if you’re working with individual events (you can of course use a simple function that aggregates events into batches yourself). If you want to work with streams of data, the reactor FluxSubscriptionModel is probably a better option since it’s using the Flux publisher from project reactor.
Note that it’s fine to use reactive FluxSubscriptionModel, even though the event store is implemented using the blocking api, and vice versa. If the datastore allows it, you can also run subscriptions in a different process than the processes reading and writing to the event store.
To get started with subscriptions refer to Using Subscriptions.
Independently of the blocking-versus-reactive choice above, a subscription is either asynchronous or synchronous. Everything so far is asynchronous: it runs on its own thread and fires after the write commits. A synchronous subscription instead runs inline on the writer thread, before execute returns, so it can update a projection in the write path and, with a transaction, atomically with the write.
There are two different kinds of subscriptions, blocking subscriptions and reactive subscriptions. For blocking subscription implementations see here and for reactive subscription implementations see here.
