Class SimpleRqueueListenerContainerFactory


  • public class SimpleRqueueListenerContainerFactory
    extends java.lang.Object
    A Factory class which can be used to create RqueueMessageListenerContainer object. Instead of going through lower level detail of RqueueMessageListenerContainer.

    Factory has multiple methods to support different types of requirements.

    • Constructor Detail

      • SimpleRqueueListenerContainerFactory

        public SimpleRqueueListenerContainerFactory()
    • Method Detail

      • getTaskExecutor

        public org.springframework.core.task.AsyncTaskExecutor getTaskExecutor()
        Get configured task executor
        Returns:
        async task executor
      • setTaskExecutor

        public void setTaskExecutor​(org.springframework.core.task.AsyncTaskExecutor taskExecutor)
        Configures the TaskExecutor which is used to poll messages and execute them by calling the handler methods. If no TaskExecutor is set, a default one is created. If you're setting this then you should set maxNumWorkers.
        Parameters:
        taskExecutor - The TaskExecutor used by the container.
        See Also:
        RqueueMessageListenerContainer.createDefaultTaskExecutor(List), setMaxNumWorkers(int)
      • getAutoStartup

        public java.lang.Boolean getAutoStartup()
      • getRqueueMessageHandler

        public RqueueMessageHandler getRqueueMessageHandler()
        Return configured message handler
        Returns:
        RqueueMessageHandler object
      • setRqueueMessageHandler

        public void setRqueueMessageHandler​(RqueueMessageHandler rqueueMessageHandler)
        Set message handler, this can be used to set custom message handlers that could have some special features apart of the default one
        Parameters:
        rqueueMessageHandler - RqueueMessageHandler object
      • getBackOffTime

        public long getBackOffTime()
        Returns:
        The number of milliseconds the polling thread must wait before trying to recover when an error occurs (e.g. connection timeout)
      • setBackOffTime

        public void setBackOffTime​(long backOffTime)
        The number of milliseconds the polling thread must wait before trying to recover when an error occurs (e.g. connection timeout). Default value is 10000 milliseconds.
        Parameters:
        backOffTime - in milliseconds.
      • getMaxNumWorkers

        public java.lang.Integer getMaxNumWorkers()
      • setMaxNumWorkers

        public void setMaxNumWorkers​(int maxNumWorkers)
        Maximum number of workers, that would be used to run tasks. The default size which is 2 threads for every queue.

        When you're using custom executor then you should set this number as (thread pool max size - number of queues) given executor is not shared. The maxNumWorkers tells how many workers you want to run in parallel for all listeners, for example if you have 3 listeners, and you have set this as 10 then all 3 listeners would be running maximum **combined 10 jobs** at any point of time.

        What would happen if I set this to very high value while using custom executor?
        1. Task(s) would be rejected by the executor unless queue size is non-zero
        2. When queue size is non-zero then it can create duplicate message problem, since the polled message has not been processed yet. This will happen when RqueueListener.visibilityTimeout() is smaller than the time a task took to execute from the time of polling to final execution.

        Parameters:
        maxNumWorkers - Maximum number of workers.
      • getMessageConverters

        @Deprecated
        public java.util.List<org.springframework.messaging.converter.MessageConverter> getMessageConverters()
        Deprecated.
        Returns:
        the message converters
      • setMessageConverters

        @Deprecated
        public void setMessageConverters​(java.util.List<org.springframework.messaging.converter.MessageConverter> messageConverters)
        For message (de)serialization we might need one or more message converters, configure those message converters
        Parameters:
        messageConverters - list of message converters
      • getMessageConverter

        public org.springframework.messaging.converter.MessageConverter getMessageConverter()
        Returns:
        the message converter
      • setMessageConverter

        public void setMessageConverter​(org.springframework.messaging.converter.MessageConverter messageConverter)
        A default message converter DefaultRqueueMessageConverter is added that can handle all type of data serialization/deserialization and all data is serialized to and from JSON. You can use other mechanism to serialize/deserialize class object like MessagePack or any other format.
        Parameters:
        messageConverter - the message converter
      • getRedisConnectionFactory

        public org.springframework.data.redis.connection.RedisConnectionFactory getRedisConnectionFactory()
        Returns:
        get Redis connection factor
      • setRedisConnectionFactory

        public void setRedisConnectionFactory​(org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory)
        Set redis connection factory, that would be used to configured message template and other components
        Parameters:
        redisConnectionFactory - redis connection factory object
      • getRqueueMessageTemplate

        public RqueueMessageTemplate getRqueueMessageTemplate()
        Returns:
        message template
      • setRqueueMessageTemplate

        public void setRqueueMessageTemplate​(RqueueMessageTemplate messageTemplate)
        Set RqueueMessageTemplate that's used to pull and push messages from/to Redis.
        Parameters:
        messageTemplate - a message template object.
      • getDiscardMessageProcessor

        public MessageProcessor getDiscardMessageProcessor()
      • setDiscardMessageProcessor

        public void setDiscardMessageProcessor​(MessageProcessor discardMessageProcessor)
        This message processor would be called whenever a message is discarded due to retry limit exhaust.
        Parameters:
        discardMessageProcessor - object of the discard message processor.
      • getDeadLetterQueueMessageProcessor

        public MessageProcessor getDeadLetterQueueMessageProcessor()
      • setDeadLetterQueueMessageProcessor

        public void setDeadLetterQueueMessageProcessor​(MessageProcessor deadLetterQueueMessageProcessor)
        This message processor would be called whenever a message is moved to dead letter queue
        Parameters:
        deadLetterQueueMessageProcessor - object of message processor.
      • getManualDeletionMessageProcessor

        public MessageProcessor getManualDeletionMessageProcessor()
      • setManualDeletionMessageProcessor

        public void setManualDeletionMessageProcessor​(MessageProcessor manualDeletionMessageProcessor)
        Set a message processor would be called whenever a manual deletion message is encounter during execution.
        Parameters:
        manualDeletionMessageProcessor - object of message processor.
      • getPostExecutionMessageProcessor

        public MessageProcessor getPostExecutionMessageProcessor()
      • setPostExecutionMessageProcessor

        public void setPostExecutionMessageProcessor​(MessageProcessor postExecutionMessageProcessor)
        A message processor would be called whenever a consumer has successfully consumed the given message.
        Parameters:
        postExecutionMessageProcessor - object of message processor.
      • getPreExecutionMessageProcessor

        public MessageProcessor getPreExecutionMessageProcessor()
      • setPreExecutionMessageProcessor

        public void setPreExecutionMessageProcessor​(MessageProcessor preExecutionMessageProcessor)
        A message processor that can control the execution of any task, this message processor would be called multiple time, in case of retry, so application should be able to handle this. If this message processor returns false then message won't be executed, it will be considered that task has to be deleted.
        Parameters:
        preExecutionMessageProcessor - pre execution message processor.
      • getPollingInterval

        public long getPollingInterval()
        Get configured polling interval
        Returns:
        the time in milli seconds
      • setPollingInterval

        public void setPollingInterval​(long pollingInterval)
        Set polling time interval, this controls the listener polling interval
        Parameters:
        pollingInterval - time in milli seconds
      • getTaskExecutionBackOff

        public TaskExecutionBackOff getTaskExecutionBackOff()
        Return the task execution back-off
        Returns:
        the back-off provider
      • setTaskExecutionBackOff

        public void setTaskExecutionBackOff​(TaskExecutionBackOff taskExecutionBackOff)
        Set custom task executor back-off.
        Parameters:
        taskExecutionBackOff - task execution back-off.
      • setPriorityMode

        public void setPriorityMode​(PriorityMode priorityMode)
        Set priority mode for queues.
        Parameters:
        priorityMode - strict or weighted.
      • getMessageHeaders

        public org.springframework.messaging.MessageHeaders getMessageHeaders()
      • setMessageHeaders

        public void setMessageHeaders​(org.springframework.messaging.MessageHeaders messageHeaders)
      • setInspectAllBean

        public void setInspectAllBean​(boolean inspectAllBean)
        Rqueue scans all beans to find method annotated with RqueueListener.

        Scanning all beans can slow the bootstrap process, by default this is enabled, but using MessageListener the scanned beans can be limited.

        If you just want to scan specific beans for RqueueListener annotated methods, than set inspectAllBean to false and annotate your message listener classes with MessageListener

        Parameters:
        inspectAllBean - whether all beans should be inspected for RqueueListener or not
        See Also:
        MessageListener
      • getMiddlewares

        public java.util.List<Middleware> getMiddlewares()
        Get configured middlewares
        Returns:
        list of middlewares or null
      • setMiddlewares

        public void setMiddlewares​(java.util.List<Middleware> middlewares)
        Add middlewares those would be used while processing a message. Middlewares are called in the order they are added.
        Parameters:
        middlewares - list of middlewares
      • useMiddleware

        public void useMiddleware​(Middleware middleware)
        Add a given middleware in the chain
        Parameters:
        middleware - middleware
      • getReactiveRedisConnectionFactory

        public org.springframework.data.redis.connection.ReactiveRedisConnectionFactory getReactiveRedisConnectionFactory()
      • setReactiveRedisConnectionFactory

        public void setReactiveRedisConnectionFactory​(org.springframework.data.redis.connection.ReactiveRedisConnectionFactory reactiveRedisConnectionFactory)
        Set Reactive redis connection factory
        Parameters:
        reactiveRedisConnectionFactory - reactive redis connection factory to be used