Reputation: 75
I have a queue which is getting consumed by an Spring Boot application. As my Spring Boot application is waiting for response from a REST API its not able to process the incoming messages faster due to which the number of pending messages is increasing on my queue.
I have done some R&D and came out with the solution which is mentioned below. Kindly help me by reviewing the solution so that I can know whether I am on a right track.
My current ActiveMQ configuration:
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(activeMQConnectionFactory());
factory.setConcurrency("1-1");
return factory;
}
@Bean
public ActiveMQConnectionFactory activeMQConnectionFactory() {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
factory.setBrokerURL(brokerURL);
factory.setUserName(userName);
factory.setPassword(password);
return factory;
}
My planning for solution:-
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(activeMQConnectionFactory());
factory.setConcurrency("1-50");
factory.setMaxMessagesPerTask(10);
factory.setReceiveTimeout(5000L); // 5 seconds
return factory;
}
@Bean
public ActiveMQConnectionFactory activeMQConnectionFactory() {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
factory.setBrokerURL(brokerURL);
factory.setUserName(userName);
factory.setPassword(password);
ActiveMQPrefetchPolicy policy = new ActiveMQPrefetchPolicy();
policy.setQueuePrefetch(1);
factory.setPrefetchPolicy(policy);
return factory;
}
Upvotes: 0
Views: 263
Reputation: 35152
Generally speaking, more consumers (especially concurrent consumers) will process messages more quickly than fewer consumers so this looks good from that perspective.
Upvotes: 1