public interface MessageListenerContainer extends SmartLifecycle
DEFAULT_PHASE
getPhase, isAutoStartup, stop
static MessageListenerContainer create(MongoTemplate template)
MessageListenerContainer
given MongoTemplate
.template
- must not be null.MessageListenerContainer
using MongoTemplate
.default <T> Subscription register(SubscriptionRequest<T,Object,? extends SubscriptionRequest.RequestOptions> request)
SubscriptionRequest
in the container. If the is
already running
the Subscription
will be added and run immediately, otherwise it'll be scheduled and
started once the container is actually started
.
MessageListenerContainer container = ...
MessageListener, Object> messageListener = (message) -> message....
ChangeStreamRequest
Errors during Message
retrieval lead to cannelation
of the underlying task.request
- must not be null.<S,T> Subscription register(SubscriptionRequest<S,? super T,? extends SubscriptionRequest.RequestOptions> request, Class<T> bodyType)
SubscriptionRequest
in the container. If the is
already running
the Subscription
will be added and run immediately, otherwise it'll be scheduled and
started once the container is actually started
.
MessageListenerContainer container = ...
MessageListener, Document> messageListener = (message) -> message.getBody().toJson();
ChangeStreamRequest request = new ChangeStreamRequest<>(messageListener, () -> "collection-name");
Subscription subscription = container.register(request, Document.class);
On Lifecycle.stop()
all subscriptions
are cancelled prior to shutting
down the container itself.
Registering the very same SubscriptionRequest
more than once simply returns the already existing
Subscription
.
Unless a Subscription
is removed
form the container, the Subscription
is restarted once the container itself is restarted.
Errors during Message
retrieval lead to cannelation
of the underlying task.request
- must not be null.bodyType
- the exact target or a more concrete type of the Message.getBody()
.<S,T> Subscription register(SubscriptionRequest<S,? super T,? extends SubscriptionRequest.RequestOptions> request, Class<T> bodyType, ErrorHandler errorHandler)
SubscriptionRequest
in the container. If the is
already running
the Subscription
will be added and run immediately, otherwise it'll be scheduled and
started once the container is actually started
.
MessageListenerContainer container = ...
MessageListener, Document> messageListener = (message) -> message.getBody().toJson();
ChangeStreamRequest request = new ChangeStreamRequest<>(messageListener, () -> "collection-name");
Subscription subscription = container.register(request, Document.class);
On Lifecycle.stop()
all subscriptions
are cancelled prior to shutting
down the container itself.
Registering the very same SubscriptionRequest
more than once simply returns the already existing
Subscription
.
Unless a Subscription
is removed
form the container, the Subscription
is restarted once the container itself is restarted.
Errors during Message
retrieval are delegated to the given ErrorHandler
.request
- must not be null.bodyType
- the exact target or a more concrete type of the Message.getBody()
. Must not be null.errorHandler
- the callback to invoke when retrieving the Message
from the data source fails for some
reason.void remove(Subscription subscription)
Subscription
from the container. This prevents the Subscription
to be restarted
in a potential stop
/start
scenario.active
subcription
is cancelled
prior to removal.subscription
- must not be null.Optional<Subscription> lookup(SubscriptionRequest<?,?,?> request)
SubscriptionRequest
within the container and return the associated Subscription
if
present.request
- must not be null.Optional.empty()
if not set.Copyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.