Class SimpleMessageListenerContainer

    • Field Detail

      • DEFAULT_RECEIVE_TIMEOUT

        public static final long DEFAULT_RECEIVE_TIMEOUT
        See Also:
        Constant Field Values
    • Constructor Detail

      • SimpleMessageListenerContainer

        public SimpleMessageListenerContainer()
        Default constructor for convenient dependency injection via setters.
      • SimpleMessageListenerContainer

        public SimpleMessageListenerContainer​(ConnectionFactory connectionFactory)
        Create a listener container from the connection factory (mandatory).
        Parameters:
        connectionFactory - the ConnectionFactory
    • Method Detail

      • setConcurrentConsumers

        public void setConcurrentConsumers​(int concurrentConsumers)
        Specify the number of concurrent consumers to create. Default is 1.

        Raising the number of concurrent consumers is recommended in order to scale the consumption of messages coming in from a queue. However, note that any ordering guarantees are lost once multiple consumers are registered. In general, stick with 1 consumer for low-volume queues. Cannot be more than maxConcurrentConsumers (if set).

        Parameters:
        concurrentConsumers - the minimum number of consumers to create.
        See Also:
        setMaxConcurrentConsumers(int)
      • setConcurrency

        public void setConcurrency​(java.lang.String concurrency)
        Specify concurrency limits via a "lower-upper" String, e.g. "5-10", or a simple upper limit String, e.g. "10" (a fixed number of consumers).

        This listener container will always hold on to the minimum number of consumers (setConcurrentConsumers(int)) and will slowly scale up to the maximum number of consumers setMaxConcurrentConsumers(int) in case of increasing load.

        Parameters:
        concurrency - the concurrency.
        Since:
        2.0
      • setExclusive

        public final void setExclusive​(boolean exclusive)
        Set to true for an exclusive consumer - if true, the concurrency must be 1.
        Overrides:
        setExclusive in class AbstractMessageListenerContainer
        Parameters:
        exclusive - true for an exclusive consumer.
      • setReceiveTimeout

        public void setReceiveTimeout​(long receiveTimeout)
        The time (in milliseconds) that a consumer should wait for data. Default 1000 (1 second).
        Parameters:
        receiveTimeout - the timeout.
        See Also:
        setConsecutiveIdleTrigger(int)
      • setConsumerBatchEnabled

        public void setConsumerBatchEnabled​(boolean consumerBatchEnabled)
        Set to true to present a list of messages based on the setBatchSize(int), if the listener supports it. This will coerce deBatchingEnabled to true as well.
        Parameters:
        consumerBatchEnabled - true to create message batches in the container.
        Since:
        2.2
        See Also:
        setBatchSize(int)
      • isConsumerBatchEnabled

        public boolean isConsumerBatchEnabled()
        Description copied from interface: MessageListenerContainer
        Return true if this container is capable of (and configured to) create batches of consumed messages.
        Returns:
        true if enabled.
      • setMissingQueuesFatal

        public void setMissingQueuesFatal​(boolean missingQueuesFatal)
        If all of the configured queue(s) are not available on the broker, this setting determines whether the condition is fatal. When true, and the queues are missing during startup, the context refresh() will fail.

        When false, the condition is not considered fatal and the container will continue to attempt to start the consumers.

        When true, if the queues are removed while the container is running, the container is stopped.

        Defaults to true for this container.

        Overrides:
        setMissingQueuesFatal in class AbstractMessageListenerContainer
        Parameters:
        missingQueuesFatal - the missingQueuesFatal to set.
        See Also:
        AbstractMessageListenerContainer.setAutoDeclare(boolean)
      • addQueueNames

        public void addQueueNames​(java.lang.String... queueName)
        Add queue(s) to this container's list of queues. The existing consumers will be cancelled after they have processed any pre-fetched messages and new consumers will be created. The queue must exist to avoid problems when restarting the consumers.
        Overrides:
        addQueueNames in class AbstractMessageListenerContainer
        Parameters:
        queueName - The queue to add.
      • removeQueueNames

        public boolean removeQueueNames​(java.lang.String... queueName)
        Remove queues from this container's list of queues. The existing consumers will be cancelled after they have processed any pre-fetched messages and new consumers will be created. At least one queue must remain.
        Overrides:
        removeQueueNames in class AbstractMessageListenerContainer
        Parameters:
        queueName - The queue to remove.
        Returns:
        the boolean result of removal on the target queueNames List.
      • addQueues

        public void addQueues​(Queue... queue)
        Add queue(s) to this container's list of queues. The existing consumers will be cancelled after they have processed any pre-fetched messages and new consumers will be created. The queue must exist to avoid problems when restarting the consumers.
        Overrides:
        addQueues in class AbstractMessageListenerContainer
        Parameters:
        queue - The queue to add.
      • removeQueues

        public boolean removeQueues​(Queue... queue)
        Remove queues from this container's list of queues. The existing consumers will be cancelled after they have processed any pre-fetched messages and new consumers will be created. At least one queue must remain.
        Overrides:
        removeQueues in class AbstractMessageListenerContainer
        Parameters:
        queue - The queue to remove.
        Returns:
        the boolean result of removal on the target queueNames List.
      • setRetryDeclarationInterval

        public void setRetryDeclarationInterval​(long retryDeclarationInterval)
        When consuming multiple queues, set the interval between declaration attempts when only a subset of the queues were available (milliseconds).
        Parameters:
        retryDeclarationInterval - the interval, default 60000.
        Since:
        1.3.9
      • setConsumerStartTimeout

        public void setConsumerStartTimeout​(long consumerStartTimeout)
        When starting a consumer, if this time (ms) elapses before the consumer starts, an error log is written; one possible cause would be if the taskExecutor has insufficient threads to support the container concurrency. Default 60000.
        Parameters:
        consumerStartTimeout - the timeout.
        Since:
        1.7.5
      • sharedConnectionEnabled

        protected final boolean sharedConnectionEnabled()
        Always use a shared Rabbit Connection.
        Returns:
        true
      • doStart

        protected void doStart()
        Re-initializes this container's Rabbit message consumers, if not initialized already. Then submits each consumer to this container's task executor.
        Overrides:
        doStart in class AbstractMessageListenerContainer
      • stop

        public void stop​(java.lang.Runnable callback)
      • initializeConsumers

        protected int initializeConsumers()
      • adjustConsumers

        protected void adjustConsumers​(int deltaArg)
        Adjust consumers depending on delta.
        Parameters:
        deltaArg - a negative value increases, positive decreases.
        Since:
        1.7.8
      • addAndStartConsumers

        protected void addAndStartConsumers​(int delta)
        Start up to delta consumers, limited by setMaxConcurrentConsumers(int).
        Parameters:
        delta - the consumers to add.
      • handleStartupFailure

        protected void handleStartupFailure​(BackOffExecution backOffExecution)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object