为何SimpleJmsListenerContainerFactory不支持配置并发消费者?
SimpleJmsListenerContainerFactory Doesn't Support concurrentConsumers for SimpleMessageListenerContainer Great question! Let’s break down the core reasons behind this design choice, and address whether concurrent configuration for SimpleMessageListenerContainer is recommended:
1. Container Evolution & Factory Design Intent
SimpleMessageListenerContainer is one of Spring’s older JMS listener containers, built for fixed-concurrency scenarios with a straightforward thread model. However, SimpleJmsListenerContainerFactory is tailored to work with Spring’s modern @JmsListener annotation ecosystem—and by default, it creates DefaultMessageListenerContainer instances, not SimpleMessageListenerContainer.
The factory doesn’t expose concurrentConsumers because it’s optimized for more flexible, feature-rich containers like DefaultMessageListenerContainer and SimpleAsyncMessageListenerContainer. These newer containers use a more powerful concurrency model, making the legacy concurrentConsumers property irrelevant for the factory’s intended use case.
2. Unified Concurrency Configuration Model
Instead of the fixed concurrentConsumers value from the older container, the modern configuration model (backed by the factory) uses the concurrency property. This property supports range values (e.g., "2-4"), allowing dynamic adjustment of concurrent consumers based on workload—something the fixed concurrentConsumers count can’t handle.
The factory is designed to enforce this unified model, so it doesn’t surface the legacy property to avoid confusion between different container types and their configuration patterns.
3. Is Concurrent Configuration for SimpleMessageListenerContainer Recommended?
It’s not strictly forbidden, but it’s generally not recommended for most modern use cases:
SimpleMessageListenerContaineruses a fixed thread pool with no dynamic scaling, which can be inefficient for variable workloads.- It lacks advanced features like automatic connection failure recovery, dynamic destination resolution, and flexible retry mechanisms that
DefaultMessageListenerContainerprovides. - If you absolutely need to use
SimpleMessageListenerContainerwith fixed concurrency, you can bypass the factory entirely: create the container instance manually, setconcurrentConsumersdirectly, and register it with your application context. Alternatively, you can extendSimpleJmsListenerContainerFactoryto add support for this property.
内容的提问来源于stack exchange,提问作者Emman Sun

