Announcement Announcement Module
Collapse
No announcement yet.
Setting MesageSelector value to in runtime to SimpleMessageListenerContainer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting MesageSelector value to in runtime to SimpleMessageListenerContainer

    Hi,

    I am using MessageListenerAdapter for my Message Driven Pojo to listen to a queue and grab messages selectively. The MessageListenerAdapter is working fine to convert the message and delegate to another class. But I am having trouble to set the message selector from my java class. Below is my context xml file.

    <bean id="responseListenerContainer" class="org.springframework.jms.listener.SimpleMess ageListenerContainer">
    <property name="concurrentConsumers" value="1"/> <!-- JMS connection -->
    <property name="connectionFactory" ref="jmsQueueConnectionFactory"></property>
    <property name="destination" ref="responseDestination" />
    <property name="messageListener">
    <bean id="responseMsgListener" class="org.springframework.jms.listener.adapter.Me ssageListenerAdapter">
    <property name="messageConverter" ref="analyticMessageConvertor"></property>
    <property name="delegate" ref="responseConsumer"/>
    <property name="defaultListenerMethod" value="recieve"/>
    </bean>
    </property>
    </bean>


    In my java class I am setting MesageSelector as below -

    Code:
    String messageSelector= "BatchType = '"+ mainBatchId +"'";
    SimpleMessageListenerContainer responseListenerContainer = (SimpleMessageListenerContainer) msgApplicationContext.getBean("responseListenerContainer");
    responseListenerContainer.setMessageSelector(messageSelector);
    My understanding is as I am using the Spring implementation for MessageListener, the Spring should pass the selector value to undelying MessageListener.

    I might be missing something obvious but it seems the SimpleMessageListenerContainer is not property passing the MessageSeletor value to the MessageListener through thier MessageListenerAdapter. I also tried to stop(), start(), initialize(), shutdown() the SimpleMessageListenerContainer before and after setting the the MessageSelector to container.

    Any pointer will be greatly appreciated.

    Thanks,
    Last edited by nharnwal; Nov 8th, 2007, 05:23 PM.

  • #2
    hi,

    i ran into a similar problem and after looking at the spring listeners code i decided to write my own listener.
    Think about the following:
    You change the selector, you cannot simply switch, you have to recreate the consumer. So there is a short timeframe where you have no consumer (you just closed the old one, and create the new one in the next line). If you dont use a durable subscription this can get odd since you might "loose" a message in this short period (depending on your setup and load likely or not). I found no convenient way to do this with the spring container... .

    But maybe somebody else has =).

    regards oliver

    Comment

    Working...
    X