Interface MessageListenerContainer
- All Superinterfaces:
Lifecycle
,Phased
,SmartLifecycle
- All Known Implementing Classes:
DefaultMessageListenerContainer
Internal abstraction used by the framework representing a message listener container. Not meant to
be implemented externally.
- Since:
- 2.1
- Author:
- Christoph Strobl
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Method Summary
Modifier and TypeMethodDescriptionstatic MessageListenerContainer
create
(MongoTemplate template) Create a newMessageListenerContainer
givenMongoTemplate
.lookup
(SubscriptionRequest<?, ?, ?> request) Lookup the givenSubscriptionRequest
within the container and return the associatedSubscription
if present.<S,
T> Subscription register
(SubscriptionRequest<S, ? super T, ? extends SubscriptionRequest.RequestOptions> request, Class<T> bodyType) Register a newSubscriptionRequest
in the container.<S,
T> Subscription register
(SubscriptionRequest<S, ? super T, ? extends SubscriptionRequest.RequestOptions> request, Class<T> bodyType, ErrorHandler errorHandler) Register a newSubscriptionRequest
in the container.default <T> Subscription
register
(SubscriptionRequest<T, Object, ? extends SubscriptionRequest.RequestOptions> request) Register a newSubscriptionRequest
in the container.void
remove
(Subscription subscription) Unregister a givenSubscription
from the container.Methods inherited from interface org.springframework.context.SmartLifecycle
getPhase, isAutoStartup, stop
-
Method Details
-
create
Create a newMessageListenerContainer
givenMongoTemplate
.- Parameters:
template
- must not be null.- Returns:
- a new
MessageListenerContainer
usingMongoTemplate
.
-
register
default <T> Subscription register(SubscriptionRequest<T, Object, ? extends SubscriptionRequest.RequestOptions> request) Register a newSubscriptionRequest
in the container. If theis already running
theSubscription
will be added and run immediately, otherwise it'll be scheduled and started once the container is actuallystarted
.MessageListenerContainer container = ... MessageListener<ChangeStreamDocument<Document>, Object> messageListener = (message) -> message.... ChangeStreamRequest<Object> request = new ChangeStreamRequest<>(messageListener, () -> "collection-name"); Subscription subscription = container.register(request);
Message
retrieval lead tocannelation
of the underlying task.- Parameters:
request
- must not be null.- Returns:
- never null.
-
register
<S,T> Subscription register(SubscriptionRequest<S, ? super T, ? extends SubscriptionRequest.RequestOptions> request, Class<T> bodyType) Register a newSubscriptionRequest
in the container. If theis already running
theSubscription
will be added and run immediately, otherwise it'll be scheduled and started once the container is actuallystarted
.MessageListenerContainer container = ... MessageListener<ChangeStreamDocument<Document>, Document> messageListener = (message) -> message.getBody().toJson(); ChangeStreamRequest<Document> request = new ChangeStreamRequest<>(messageListener, () -> "collection-name"); Subscription subscription = container.register(request, Document.class);
Lifecycle.stop()
allsubscriptions
are cancelled prior to shutting down the container itself.
Registering the very sameSubscriptionRequest
more than once simply returns the already existingSubscription
.
Unless aSubscription
isremoved
form the container, theSubscription
is restarted once the container itself is restarted.
Errors duringMessage
retrieval lead tocannelation
of the underlying task.- Parameters:
request
- must not be null.bodyType
- the exact target or a more concrete type of theMessage.getBody()
.- Returns:
- never null.
-
register
<S,T> Subscription register(SubscriptionRequest<S, ? super T, ? extends SubscriptionRequest.RequestOptions> request, Class<T> bodyType, ErrorHandler errorHandler) Register a newSubscriptionRequest
in the container. If theis already running
theSubscription
will be added and run immediately, otherwise it'll be scheduled and started once the container is actuallystarted
.MessageListenerContainer container = ... MessageListener<ChangeStreamDocument<Document>, Document> messageListener = (message) -> message.getBody().toJson(); ChangeStreamRequest<Document> request = new ChangeStreamRequest<>(messageListener, () -> "collection-name"); Subscription subscription = container.register(request, Document.class);
Lifecycle.stop()
allsubscriptions
are cancelled prior to shutting down the container itself.
Registering the very sameSubscriptionRequest
more than once simply returns the already existingSubscription
.
Unless aSubscription
isremoved
form the container, theSubscription
is restarted once the container itself is restarted.
Errors duringMessage
retrieval are delegated to the givenErrorHandler
.- Parameters:
request
- must not be null.bodyType
- the exact target or a more concrete type of theMessage.getBody()
. Must not be null.errorHandler
- the callback to invoke when retrieving theMessage
from the data source fails for some reason.- Returns:
- never null.
-
remove
Unregister a givenSubscription
from the container. This prevents theSubscription
to be restarted in a potentialstop
/start
scenario.
Anactive
subcription
iscancelled
prior to removal.- Parameters:
subscription
- must not be null.
-
lookup
Lookup the givenSubscriptionRequest
within the container and return the associatedSubscription
if present.- Parameters:
request
- must not be null.- Returns:
Optional.empty()
if not set.
-