I am trying to use DefaultMessageListenerContainer102's functionality to provide scalability (creating new threads for supporting large number of messages in queue).
Configuration is the following:
I think there's something very wrong in my thinking. MyAppMessageListenerAdapter extends MessageListenerAdapter102 to send response after logic in myapp-moduleA-message-delegate is processed. I think that it will never happened that DefaultMessageListenerContainer extends thread pool responsible for handling messages. MyAppMessageListenerAdapter blocks thread until it finishes.Code:<bean id="moduleA-message-listener" class="myapp.jms.MyAppMessageListenerAdapter"> <constructor-arg ref="myapp-moduleA-message-delegate"/> <property name="defaultListenerMethod" value="receive"/> <property name="messageConverter" ref="myapp-message-converter"/> <property name="defaultResponseDestination" ref="moduleA-response-queue"/> <property name="timeToLive" value="300000"/> </bean> <bean id="moduleA-message-container" class="org.springframework.jms.listener.DefaultMessageListenerContainer102"> <property name="concurrentConsumers" value="1"/> <property name="maxConcurrentConsumers" value="50"/> <property name="connectionFactory" ref="test-moduleA-connectionFactory" /> <property name="destination" ref="moduleA-request-queue" /> <property name="messageListener" ref="moduleA-message-listener" /> </bean>
From what I think this is what happens after receiving a message. Lets's say that there is only one consumer created so far, its property idle is set to true.
1. AbstractPollingMessageListenerContainer.doReceiveA ndExecute is called, message is received by receiveMessage
2. AsyncMessageListenerInvoker instance is used to process message. It finally invokes my adapter (by receiveAndExecite), which blocks thread until it finishes
3. adapter finishes its work and returns to AsyncMessageListenerInvoker. NOW its flag 'idle' is set to false. This is too late!
Thread is being blocked until message is handled. It cannot receive any messages, so it cannot create new threads for them.
I believe that setting this.idle to false in method invokeListener after receiveAndExecite is a feature, not a bug. But I don't see how to use this feature, which results in totally not scalable application.
How to handle this?