public class EmbeddedEventStore extends AbstractEventStore implements Lifecycle
EventStore that stores and fetches events using an EventStorageEngine. If
supported by its storage engine the embedded event store provides event tracking and replaying capabilities.
The event store can be tracked by multiple event processors simultaneously. To prevent that each event processor
needs to read from the storage engine individually the embedded event store contains a cache of the most recent
events. This cache is shared between the streams of various event processors. So, assuming an event processor
processes events fast enough and is not far behind the head of the event log it will not need a private connection to
the underlying data store. The size of the cache (in number of events) is configurable. This 'event consumption
optimization' might in some scenarios not be desirable, as it will spin up additional threads and perform some
locking operations. Hence it is switchable by using the EmbeddedEventStore.Builder.optimizeEventConsumption(boolean) upon
creation. Additionally, this can also be turned off by providing a system property with key optimize-event-consumption.
The embedded event store automatically fetches new events from the store if there is at least one registered tracking event processor present. It will do so after new events are committed to the store, as well as periodically as events may have been committed by other nodes or applications. This periodic fetch delay is configurable.
| Modifier and Type | Class and Description |
|---|---|
static class |
EmbeddedEventStore.Builder
Builder class to instantiate an
EmbeddedEventStore. |
Lifecycle.LifecycleHandler, Lifecycle.LifecycleRegistry| Modifier | Constructor and Description |
|---|---|
protected |
EmbeddedEventStore(EmbeddedEventStore.Builder builder)
Instantiate a
EmbeddedEventStore based on the fields contained in the EmbeddedEventStore.Builder. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterCommit(List<? extends EventMessage<?>> events)
Process given
events after the Unit of Work has been committed. |
static EmbeddedEventStore.Builder |
builder()
Instantiate a Builder to be able to create an
EmbeddedEventStore. |
TrackingEventStream |
openStream(TrackingToken trackingToken)
Open a stream containing all messages since given tracking token.
|
void |
registerLifecycleHandlers(Lifecycle.LifecycleRegistry handle)
Registers the activities to be executed in the various phases of an application's lifecycle.
|
void |
shutDown()
Method to invoke when the application shuts down.
|
createHeadToken, createTailToken, createTokenAt, handleSnapshotReadingError, lastSequenceNumberFor, prepareCommit, readEvents, readEvents, stagedDomainEventMessages, storageEngine, storeSnapshotcommit, intercept, publish, queuedMessages, registerDispatchInterceptor, subscribeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsubscriberegisterDispatchInterceptorcreateTokenSinceprotected EmbeddedEventStore(EmbeddedEventStore.Builder builder)
EmbeddedEventStore based on the fields contained in the EmbeddedEventStore.Builder.
Will assert that the EventStorageEngine is not null, and will throw an AxonConfigurationException if it is null.
builder - the EmbeddedEventStore.Builder used to instantiate a EmbeddedEventStore instancepublic static EmbeddedEventStore.Builder builder()
EmbeddedEventStore.
The following configurable fields have defaults:
MessageMonitor is defaulted to a NoOpMessageMonitor.EventBusSpanFactory is defaulted to a DefaultEventBusSpanFactory backed by a NoOpSpanFactory.cachedEvents is defaulted to 10000.fetchDelay is defaulted to 1000.cleanupDelay is defaulted to 10000.TimeUnit is defaulted to TimeUnit.MILLISECONDS.ThreadFactory is defaulted to AxonThreadFactory with ThreadGroup THREAD_GROUP.optimizeEventConsumption is defaulted to true.EventStorageEngine is a hard requirement and as such should be provided.EmbeddedEventStorepublic void shutDown()
protected void afterCommit(List<? extends EventMessage<?>> events)
AbstractEventBusevents after the Unit of Work has been committed. The default implementation does nothing.afterCommit in class AbstractEventBusevents - Events to be published by this Event Buspublic TrackingEventStream openStream(TrackingToken trackingToken)
StreamableMessageSourcetrackingToken of null to
open a stream containing all available messages. Note that the returned stream is infinite, so beware of
applying terminal operations to the returned stream.openStream in interface StreamableMessageSource<TrackedEventMessage<?>>trackingToken - object containing the position in the stream or null to open a stream containing all
messagespublic void registerLifecycleHandlers(@Nonnull Lifecycle.LifecycleRegistry handle)
LifecycleregisterLifecycleHandlers in interface Lifecyclehandle - the lifecycle instance to register the handlers withLifecycle.LifecycleRegistry.onShutdown(int, Runnable),
LifecycleRegistry#onShutdown(int, LifecycleHandler),
Lifecycle.LifecycleRegistry.onStart(int, Runnable),
LifecycleRegistry#onStart(int, LifecycleHandler)Copyright © 2010–2025. All rights reserved.