public class CatchupSubscriptionModel extends Object implements SubscriptionModel, DelegatingSubscriptionModel
SubscriptionModel that reads historic cloud events from the all event streams (see EventStoreQueries.all()) until caught up with the
PositionAwareSubscriptionModel.globalSubscriptionPosition() of the subscription (you probably want to narrow the historic set events of events
by using a Filter when subscribing). It'll automatically switch over to the supplied subscription when all history events are read and the subscription has caught-up.
Note that the implementation uses an in-memory cache (default size is but this can be configured using a CatchupSubscriptionModelConfig)
to reduce the number of duplicate event when switching from historic events to the current cloud event position. It's highly recommended that the application logic is idempotent if the
cache size doesn't cover all duplicate events.
Also note that the if a the subscription crashes during catch-up mode it'll continue where it left-off on restart, given the no specific `StartAt` position is supplied.
For this to work, the subscription must store the subscription position in a SubscriptionPositionStorage implementation periodically. It's possible to configure
how often this should happen in the CatchupSubscriptionModelConfig.
| Constructor and Description |
|---|
CatchupSubscriptionModel(PositionAwareSubscriptionModel subscriptionModel,
EventStoreQueries eventStoreQueries)
Create a new instance of
CatchupSubscriptionModel the uses a default CatchupSubscriptionModelConfig with a cache size of
but store the subscription position during the catch-up phase (i.e. |
CatchupSubscriptionModel(PositionAwareSubscriptionModel subscriptionModel,
EventStoreQueries eventStoreQueries,
CatchupSubscriptionModelConfig config)
Create a new instance of
CatchupSubscriptionModel the uses the supplied CatchupSubscriptionModelConfig. |
| Modifier and Type | Method and Description |
|---|---|
void |
cancelSubscription(String subscriptionId) |
SubscriptionModel |
getDelegatedSubscriptionModel() |
boolean |
isPaused(String subscriptionId) |
boolean |
isRunning() |
boolean |
isRunning(String subscriptionId) |
static boolean |
isTimeBasedSubscriptionPosition(org.occurrent.subscription.StartAt startAt) |
static boolean |
isTimeBasedSubscriptionPosition(org.occurrent.subscription.SubscriptionPosition subscriptionPosition) |
void |
pauseSubscription(String subscriptionId) |
Subscription |
resumeSubscription(String subscriptionId) |
void |
shutdown() |
void |
start() |
void |
stop() |
Subscription |
subscribe(String subscriptionId,
org.occurrent.subscription.SubscriptionFilter filter,
org.occurrent.subscription.StartAt startAt,
Consumer<io.cloudevents.CloudEvent> action) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsubscribe, subscribe, subscribegetDelegatedSubscriptionModelRecursivelypublic CatchupSubscriptionModel(PositionAwareSubscriptionModel subscriptionModel, EventStoreQueries eventStoreQueries)
CatchupSubscriptionModel the uses a default CatchupSubscriptionModelConfig with a cache size of
but store the subscription position during the catch-up phase (i.e. if the application crashes or is shutdown during the
catch-up phase then the subscription will start from the beginning on application restart). After the catch-up phase has completed, the PositionAwareSubscriptionModel
will dictate how often the subscription position is stored.subscriptionModel - The subscription that'll be used to subscribe to new events after catch-up is completed.eventStoreQueries - The API that will be used for catch-uppublic CatchupSubscriptionModel(PositionAwareSubscriptionModel subscriptionModel, EventStoreQueries eventStoreQueries, CatchupSubscriptionModelConfig config)
CatchupSubscriptionModel the uses the supplied CatchupSubscriptionModelConfig.
After catch-up mode has completed, the PositionAwareSubscriptionModel will dictate how often the subscription position is stored.subscriptionModel - The subscription that'll be used to subscribe to new events after catch-up is completed.eventStoreQueries - The API that will be used for catch-upconfig - The configuration to usepublic Subscription subscribe(String subscriptionId, org.occurrent.subscription.SubscriptionFilter filter, org.occurrent.subscription.StartAt startAt, Consumer<io.cloudevents.CloudEvent> action)
subscribe in interface Subscribablepublic void stop()
stop in interface SubscriptionModelLifeCyclepublic void start()
start in interface SubscriptionModelLifeCyclepublic boolean isRunning()
isRunning in interface SubscriptionModelLifeCyclepublic boolean isRunning(String subscriptionId)
isRunning in interface SubscriptionModelLifeCyclepublic boolean isPaused(String subscriptionId)
isPaused in interface SubscriptionModelLifeCyclepublic Subscription resumeSubscription(String subscriptionId)
resumeSubscription in interface SubscriptionModelLifeCyclepublic void pauseSubscription(String subscriptionId)
pauseSubscription in interface SubscriptionModelLifeCyclepublic void cancelSubscription(String subscriptionId)
cancelSubscription in interface SubscriptionModelLifeCycle@PreDestroy public void shutdown()
shutdown in interface SubscriptionModelLifeCyclepublic static boolean isTimeBasedSubscriptionPosition(org.occurrent.subscription.StartAt startAt)
public static boolean isTimeBasedSubscriptionPosition(org.occurrent.subscription.SubscriptionPosition subscriptionPosition)
public SubscriptionModel getDelegatedSubscriptionModel()
getDelegatedSubscriptionModel in interface DelegatingSubscriptionModelCopyright © 2022. All rights reserved.