0
votes

Would there be any issues with using two instances of DefaultMessageListenerContainer listening on the same queue with different messageSelector? Is this scenario supported (have you experimented with it)?

I want the two listeners to be able to process messages independent from the other in parallel (simultaneously). Messages will go to each listener depending on a messageSelector condition.

My setup is like this:

<bean id="messageListener1" class="com.xyz.MyListener" scope="singleton"/>
<bean id="messageListener2" class="com.xyz.MyListener" scope="singleton"/>

<bean id="listenerContainer1" class="org.springframework.jms.listener.DefaultMessageListenerContainer" scope="singleton">
    <property name="connectionFactory" ref="credentialsconnectionfactory"/>
    <property name="destination" ref="serialQueue"/>
    <property name="messageListener" ref="messageListener1"/>
    <property name="concurrentConsumers" value="1"/>
    <property name="sessionAcknowledgeModeName" value="AUTO_ACKNOWLEDGE"/>
    <property name="sessionTransacted" value="false"/>
    <property name="messageSelector" 
        value="msgName IN ('SomeMessageName1','SomeMessageName2')" />
    <property name="taskExecutor">
        <bean id="serialTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" scope="singleton">
            <property name="corePoolSize" value="1"/>
        </bean>
    </property> 
</bean>


<bean id="listenerContainer1" class="org.springframework.jms.listener.DefaultMessageListenerContainer" scope="singleton">
    <property name="connectionFactory" ref="credentialsconnectionfactory"/>
    <property name="destination" ref="serialQueue"/>
    <property name="messageListener" ref="messageListener2"/>
    <property name="concurrentConsumers" value="1"/>
    <property name="sessionAcknowledgeModeName" value="AUTO_ACKNOWLEDGE"/>
    <property name="sessionTransacted" value="false"/>
    <property name="messageSelector" value="msgName NOT IN ('SomeMessageName1','SomeMessageName2')" />
    <property name="taskExecutor">
        <bean id="serialSCMTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" scope="singleton">
            <property name="corePoolSize" value="1"/>
        </bean>
    </property> 
</bean>

I am using JBOSS EAP 6.2 (HornetQ) messaging server, Spring Framework 3.2.4 and Spring-jms- 3.0.7. I can't change technology, third-party jars or release version. Also, I cannot use a separate queue. Thanks!

1

1 Answers

0
votes

No there should not be any problems with this approach. The message selectors are there to provision selective message consumption like you configured.