We are using ActiveMQ as our message broker.
For one of the queues we found that rate at which message is produced is far higher than the rate at which messages are consumed. This sometimes results in ActiveMQ crashing.
So we are exploring the options to increase the consumption rate. (First priority is increasing rate of existing consumer and then increase number of consumer pods/instances).
Following is the current listener config
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
factory.setConcurrency("1-1");
factory.setMessageConverter(jacksonJmsMessageConverter());
return factory;
}
The listener logic interacts with a database multiple times and can be qualified as I/O bound task. So we are thinking of processing multiple messages in parallel.
We found following options.
We have set concurreny to
1-1implying thatconcurrentConsumersandmaxConcurrentConsumersare 1 and only 1 message is processed at a time. This is the configuration we can increase to say5-10so that min 5 and max 10 consumers will be able to operate concurrently.We also found that we can also set
TaskExecutorin listener factory. Like setting athreadPoolExecutor (corePoolSize = 5, maxPoolSize = 10, queueCapacity=50)will also help us to concurrently process messages.I'm unsure as which option to employ (1 or 2)
- If we increase concurrency to 5-10 and also set a ThreadPoolExecutor, what will the behaviour and impact?
- Any pointers in choosing optimal values of params?