Class CatchupSubscriptionModel
- All Implemented Interfaces:
DelegatingSubscriptionModel,Subscribable,SubscriptionModel,SubscriptionModelLifeCycle
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 100 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 Summary
ConstructorsConstructorDescriptionCatchupSubscriptionModel(PositionAwareSubscriptionModel subscriptionModel, EventStoreQueries eventStoreQueries) Create a new instance ofCatchupSubscriptionModelthe uses a defaultCatchupSubscriptionModelConfigwith a cache size of 100 but store the subscription position during the catch-up phase (i.e.CatchupSubscriptionModel(PositionAwareSubscriptionModel subscriptionModel, EventStoreQueries eventStoreQueries, CatchupSubscriptionModelConfig config) Create a new instance ofCatchupSubscriptionModelthe uses the suppliedCatchupSubscriptionModelConfig. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancelSubscription(String subscriptionId) booleanbooleanbooleanstatic booleanisTimeBasedSubscriptionPosition(org.occurrent.subscription.StartAt startAt) static booleanisTimeBasedSubscriptionPosition(org.occurrent.subscription.SubscriptionPosition subscriptionPosition) voidpauseSubscription(String subscriptionId) resumeSubscription(String subscriptionId) voidshutdown()voidstart()voidstop()subscribe(String subscriptionId, org.occurrent.subscription.SubscriptionFilter filter, org.occurrent.subscription.StartAt startAt, Consumer<io.cloudevents.CloudEvent> action) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.occurrent.subscription.api.blocking.DelegatingSubscriptionModel
getDelegatedSubscriptionModelRecursivelyMethods inherited from interface org.occurrent.subscription.api.blocking.Subscribable
subscribe, subscribe, subscribe
-
Constructor Details
-
CatchupSubscriptionModel
public CatchupSubscriptionModel(PositionAwareSubscriptionModel subscriptionModel, EventStoreQueries eventStoreQueries) Create a new instance ofCatchupSubscriptionModelthe uses a defaultCatchupSubscriptionModelConfigwith a cache size of 100 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, thePositionAwareSubscriptionModelwill dictate how often the subscription position is stored.- Parameters:
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-up
-
CatchupSubscriptionModel
public CatchupSubscriptionModel(PositionAwareSubscriptionModel subscriptionModel, EventStoreQueries eventStoreQueries, CatchupSubscriptionModelConfig config) Create a new instance ofCatchupSubscriptionModelthe uses the suppliedCatchupSubscriptionModelConfig. After catch-up mode has completed, thePositionAwareSubscriptionModelwill dictate how often the subscription position is stored.- Parameters:
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 use
-
-
Method Details
-
subscribe
public Subscription subscribe(String subscriptionId, org.occurrent.subscription.SubscriptionFilter filter, org.occurrent.subscription.StartAt startAt, Consumer<io.cloudevents.CloudEvent> action) - Specified by:
subscribein interfaceSubscribable
-
stop
public void stop()- Specified by:
stopin interfaceSubscriptionModelLifeCycle
-
start
public void start()- Specified by:
startin interfaceSubscriptionModelLifeCycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceSubscriptionModelLifeCycle
-
isRunning
- Specified by:
isRunningin interfaceSubscriptionModelLifeCycle
-
isPaused
- Specified by:
isPausedin interfaceSubscriptionModelLifeCycle
-
resumeSubscription
- Specified by:
resumeSubscriptionin interfaceSubscriptionModelLifeCycle
-
pauseSubscription
- Specified by:
pauseSubscriptionin interfaceSubscriptionModelLifeCycle
-
cancelSubscription
- Specified by:
cancelSubscriptionin interfaceSubscriptionModelLifeCycle
-
shutdown
@PreDestroy public void shutdown()- Specified by:
shutdownin interfaceSubscriptionModelLifeCycle
-
isTimeBasedSubscriptionPosition
public static boolean isTimeBasedSubscriptionPosition(org.occurrent.subscription.StartAt startAt) -
isTimeBasedSubscriptionPosition
public static boolean isTimeBasedSubscriptionPosition(org.occurrent.subscription.SubscriptionPosition subscriptionPosition) -
getDelegatedSubscriptionModel
- Specified by:
getDelegatedSubscriptionModelin interfaceDelegatingSubscriptionModel
-