Interface MessageListenerContainer

All Superinterfaces:
org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle
All Known Implementing Classes:
DefaultMessageListenerContainer

public interface MessageListenerContainer extends org.springframework.context.SmartLifecycle
Internal abstraction used by the framework representing a message listener container. Not meant to be implemented externally.
Since:
2.1
Author:
Christoph Strobl
  • Method Details

    • create

      static MessageListenerContainer create(MongoTemplate template)
      Parameters:
      template - must not be null.
      Returns:
      a new MessageListenerContainer using MongoTemplate.
    • register

      default <T> Subscription register(SubscriptionRequest<T,Object,? extends SubscriptionRequest.RequestOptions> request)
      Register a new 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<ChangeStreamDocument<Document>, Object> messageListener = (message) -> message....
           ChangeStreamRequest<Object> request = new ChangeStreamRequest<>(messageListener, () -> "collection-name");
      
           Subscription subscription = container.register(request);
       
       
      Errors during Message retrieval lead to cannelation 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 new 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<ChangeStreamDocument<Document>, Document> messageListener = (message) -> message.getBody().toJson();
           ChangeStreamRequest<Document> 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.
      Parameters:
      request - must not be null.
      bodyType - the exact target or a more concrete type of the Message.getBody().
      Returns:
      never null.
    • register

      <S, T> Subscription register(SubscriptionRequest<S,? super T,? extends SubscriptionRequest.RequestOptions> request, Class<T> bodyType, org.springframework.util.ErrorHandler errorHandler)
      Register a new 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<ChangeStreamDocument<Document>, Document> messageListener = (message) -> message.getBody().toJson();
           ChangeStreamRequest<Document> 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.
      Parameters:
      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.
      Returns:
      never null.
    • remove

      void remove(Subscription subscription)
      Unregister a given Subscription from the container. This prevents the Subscription to be restarted in a potential stop/start scenario.
      An active subcription is cancelled prior to removal.
      Parameters:
      subscription - must not be null.
    • lookup

      Optional<Subscription> lookup(SubscriptionRequest<?,?,?> request)
      Lookup the given SubscriptionRequest within the container and return the associated Subscription if present.
      Parameters:
      request - must not be null.
      Returns:
      Optional.empty() if not set.