public class DefaultMessageListenerContainer extends Object implements MessageListenerContainer
Executor based MessageListenerContainer implementation for running tasks like
listening to MongoDB Change Streams and tailable
cursors.
This message container creates long-running tasks that are executed on Executor.DEFAULT_PHASE| Constructor and Description |
|---|
DefaultMessageListenerContainer(MongoTemplate template)
Create a new
DefaultMessageListenerContainer. |
DefaultMessageListenerContainer(MongoTemplate template,
Executor taskExecutor)
Create a new
DefaultMessageListenerContainer running tasks via the given
taskExecutor. |
DefaultMessageListenerContainer(MongoTemplate template,
Executor taskExecutor,
ErrorHandler errorHandler)
Create a new
DefaultMessageListenerContainer running tasks via the given
taskExecutor delegating errors to the given ErrorHandler. |
| Modifier and Type | Method and Description |
|---|---|
int |
getPhase() |
boolean |
isAutoStartup() |
boolean |
isRunning() |
Optional<Subscription> |
lookup(SubscriptionRequest<?,?,?> request)
Lookup the given
SubscriptionRequest within the container and return the associated Subscription if
present. |
<S,T> Subscription |
register(SubscriptionRequest<S,? super T,? extends SubscriptionRequest.RequestOptions> request,
Class<T> bodyType)
Register a new
SubscriptionRequest in the container. |
<S,T> Subscription |
register(SubscriptionRequest<S,? super T,? extends SubscriptionRequest.RequestOptions> request,
Class<T> bodyType,
ErrorHandler errorHandler)
Register a new
SubscriptionRequest in the container. |
Subscription |
register(SubscriptionRequest request,
Task task) |
void |
remove(Subscription subscription)
Unregister a given
Subscription from the container. |
void |
start() |
void |
stop() |
void |
stop(Runnable callback) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreate, registerpublic DefaultMessageListenerContainer(MongoTemplate template)
DefaultMessageListenerContainer.template - must not be null.public DefaultMessageListenerContainer(MongoTemplate template, Executor taskExecutor)
DefaultMessageListenerContainer running tasks via the given
taskExecutor.template - must not be null.taskExecutor - must not be null.public DefaultMessageListenerContainer(MongoTemplate template, Executor taskExecutor, @Nullable ErrorHandler errorHandler)
DefaultMessageListenerContainer running tasks via the given
taskExecutor delegating errors to the given ErrorHandler.template - must not be null. Used by the TaskFactory.taskExecutor - must not be null.errorHandler - the default ErrorHandler to be used by tasks inside the container. Can be
null.public boolean isAutoStartup()
isAutoStartup in interface SmartLifecyclepublic void stop(Runnable callback)
stop in interface SmartLifecyclepublic int getPhase()
getPhase in interface PhasedgetPhase in interface SmartLifecyclepublic <S,T> Subscription register(SubscriptionRequest<S,? super T,? extends SubscriptionRequest.RequestOptions> request, Class<T> bodyType)
MessageListenerContainerSubscriptionRequest 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.register in interface MessageListenerContainerrequest - must not be null.public <S,T> Subscription register(SubscriptionRequest<S,? super T,? extends SubscriptionRequest.RequestOptions> request, Class<T> bodyType, ErrorHandler errorHandler)
MessageListenerContainerSubscriptionRequest 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.register in interface MessageListenerContainerrequest - must not be null.errorHandler - the callback to invoke when retrieving the Message from the data source fails for some
reason.public Optional<Subscription> lookup(SubscriptionRequest<?,?,?> request)
MessageListenerContainerSubscriptionRequest within the container and return the associated Subscription if
present.lookup in interface MessageListenerContainerrequest - must not be null.Optional.empty() if not set.public Subscription register(SubscriptionRequest request, Task task)
public void remove(Subscription subscription)
MessageListenerContainerSubscription from the container. This prevents the Subscription to be restarted
in a potential stop/start scenario.active subcription is cancelled prior to removal.remove in interface MessageListenerContainersubscription - must not be null.Copyright © 2011–2019 Pivotal Software, Inc.. All rights reserved.