Class SimpleRqueueListenerContainerFactory
- java.lang.Object
-
- com.github.sonus21.rqueue.config.SimpleRqueueListenerContainerFactory
-
public class SimpleRqueueListenerContainerFactory extends java.lang.Object
A Factory class which can be used to createRqueueMessageListenerContainer
object. Instead of going through lower level detail ofRqueueMessageListenerContainer
.Factory has multiple methods to support different types of requirements.
-
-
Constructor Summary
Constructors Constructor Description SimpleRqueueListenerContainerFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RqueueMessageListenerContainer
createMessageListenerContainer()
Creates aRqueueMessageListenerContainer
container.java.lang.Boolean
getAutoStartup()
long
getBackOffTime()
MessageProcessor
getDeadLetterQueueMessageProcessor()
MessageProcessor
getDiscardMessageProcessor()
MessageProcessor
getManualDeletionMessageProcessor()
java.lang.Integer
getMaxNumWorkers()
org.springframework.messaging.converter.MessageConverter
getMessageConverter()
java.util.List<org.springframework.messaging.converter.MessageConverter>
getMessageConverters()
Deprecated.org.springframework.messaging.MessageHeaders
getMessageHeaders()
java.util.List<Middleware>
getMiddlewares()
Get configured middlewareslong
getPollingInterval()
Get configured polling intervalMessageProcessor
getPostExecutionMessageProcessor()
MessageProcessor
getPreExecutionMessageProcessor()
PriorityMode
getPriorityMode()
org.springframework.data.redis.connection.ReactiveRedisConnectionFactory
getReactiveRedisConnectionFactory()
org.springframework.data.redis.connection.RedisConnectionFactory
getRedisConnectionFactory()
RqueueMessageHandler
getRqueueMessageHandler()
Return configured message handlerRqueueMessageTemplate
getRqueueMessageTemplate()
TaskExecutionBackOff
getTaskExecutionBackOff()
Return the task execution back-offorg.springframework.core.task.AsyncTaskExecutor
getTaskExecutor()
Get configured task executorvoid
setAutoStartup(boolean autoStartup)
Configures ifRqueueMessageListenerContainer
container should be automatically started.void
setBackOffTime(long backOffTime)
The number of milliseconds the polling thread must wait before trying to recover when an error occurs (e.g.void
setDeadLetterQueueMessageProcessor(MessageProcessor deadLetterQueueMessageProcessor)
This message processor would be called whenever a message is moved to dead letter queuevoid
setDiscardMessageProcessor(MessageProcessor discardMessageProcessor)
This message processor would be called whenever a message is discarded due to retry limit exhaust.void
setInspectAllBean(boolean inspectAllBean)
Rqueue scans all beans to find method annotated withRqueueListener
.void
setManualDeletionMessageProcessor(MessageProcessor manualDeletionMessageProcessor)
Set a message processor would be called whenever a manual deletion message is encounter during execution.void
setMaxNumWorkers(int maxNumWorkers)
Maximum number of workers, that would be used to run tasks.void
setMessageConverter(org.springframework.messaging.converter.MessageConverter messageConverter)
A default message converterDefaultRqueueMessageConverter
is added that can handle all type of data serialization/deserialization and all data is serialized to and from JSON.void
setMessageConverters(java.util.List<org.springframework.messaging.converter.MessageConverter> messageConverters)
Deprecated.void
setMessageHeaders(org.springframework.messaging.MessageHeaders messageHeaders)
void
setMiddlewares(java.util.List<Middleware> middlewares)
Add middlewares those would be used while processing a message.void
setPollingInterval(long pollingInterval)
Set polling time interval, this controls the listener polling intervalvoid
setPostExecutionMessageProcessor(MessageProcessor postExecutionMessageProcessor)
A message processor would be called whenever a consumer has successfully consumed the given message.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.void
setPriorityMode(PriorityMode priorityMode)
Set priority mode for queues.void
setReactiveRedisConnectionFactory(org.springframework.data.redis.connection.ReactiveRedisConnectionFactory reactiveRedisConnectionFactory)
Set Reactive redis connection factoryvoid
setRedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory)
Set redis connection factory, that would be used to configured message template and other componentsvoid
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 onevoid
setRqueueMessageTemplate(RqueueMessageTemplate messageTemplate)
Set RqueueMessageTemplate that's used to pull and push messages from/to Redis.void
setTaskExecutionBackOff(TaskExecutionBackOff taskExecutionBackOff)
Set custom task executor back-off.void
setTaskExecutor(org.springframework.core.task.AsyncTaskExecutor taskExecutor)
Configures theTaskExecutor
which is used to poll messages and execute them by calling the handler methods.void
useMiddleware(Middleware middleware)
Add a given middleware in the chain
-
-
-
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 theTaskExecutor
which is used to poll messages and execute them by calling the handler methods. If noTaskExecutor
is set, a default one is created. If you're setting this then you should setmaxNumWorkers
.- Parameters:
taskExecutor
- TheTaskExecutor
used by the container.- See Also:
RqueueMessageListenerContainer.createDefaultTaskExecutor(List)
,setMaxNumWorkers(int)
-
getAutoStartup
public java.lang.Boolean getAutoStartup()
-
setAutoStartup
public void setAutoStartup(boolean autoStartup)
Configures ifRqueueMessageListenerContainer
container should be automatically started. The default value is true.Setting this to false means, you must call start, stop and destroy methods of
RqueueMessageListenerContainer.start()
,RqueueMessageListenerContainer.stop()
,RqueueMessageListenerContainer.destroy()
- Parameters:
autoStartup
- - false if the container will be manually started
-
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 whenRqueueListener.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)
Deprecated.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 converterDefaultRqueueMessageConverter
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.
-
createMessageListenerContainer
public RqueueMessageListenerContainer createMessageListenerContainer()
Creates aRqueueMessageListenerContainer
container. To create this container we would need redis connection factoryRedisConnectionFactory
as well as message handlerRqueueMessageHandler
.- Returns:
- an object of
RqueueMessageListenerContainer
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.
-
getPriorityMode
public PriorityMode getPriorityMode()
-
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 withRqueueListener
.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 setinspectAllBean
to false and annotate your message listener classes withMessageListener
- Parameters:
inspectAllBean
- whether all beans should be inspected forRqueueListener
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
-
-