Announcement Announcement Module
Collapse
No announcement yet.
How to run DefaultMessageListenerContainer on the 'main' thread Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to run DefaultMessageListenerContainer on the 'main' thread

    I have a case where i want to run DefaultMessageListenerContainer in the same 'main' thread. Right now it uses SimpleAsyncTaskExecutor which spawns new thread every time it receives a message.

    We have a test case which connects to different distributed system and do the processing and in the end it asserts few things. As DefaultMessageListenerContainer runs in seperate thread, main thread returns and start executing assertions before DefaultMessageListenerContainer can complete. This leads to failure of the test case. As work around we have made the main thread to sleep for few seconds.

    Sample config

    <int-jms:message-driven-channel-adapter
    id="mq.txbus.publisher.channel.adapter"
    container="defaultMessageListenerContainer"
    channel="inbound.endpoint.publisher"
    acknowledge="transacted"
    extract-payload="true"/>

    <beans:bean id="defaultMessageListenerContainer" class="org.springframework.jms.listener.DefaultMes sageListenerContainer">
    <beansroperty name="connectionFactory" ref="mockConnectionFactory"/>
    <beansroperty name="destination" ref="publisherToTxmQueue"/>
    <beansroperty name="taskExecutor" ref="taskExecutor"/>
    <beansroperty name="maxMessagesPerTask" value="10"/>
    <beansroperty name="sessionTransacted" value="true"/>
    </beans:bean>

    <beans:bean id="taskExecutor" class="org.springframework.scheduling.timer.TimerT askExecutor"/>


    I am trying to use TimerTaskExecutor here because it creates single thread but that thread is seperate than main thread so problem is unresolved. I tried using SyncTaskExecutor but that does not work either (or may be i dint provide the correct property value?).

  • #2
    You can't have a MessageListener container running in the main thread, because it must run in the background (even if there is only one thread dedicated to that container). Otherwise, it would cause the main thread to hang completely (i.e. even the startup of an ApplicationContext would not be able to proceed once the lifecycle processing kicks in and the ML container is started).

    Can you provide the relevant code from your test case so we can possibly offer some suggestions?

    Comment


    • #3
      Thanks Mark! This makes sense. Basically it is a integration test where 5 different components are involved and communication is done over JMS. I have got some idea on how to implement this after reading Tomasz reply on below thread.
      http://stackoverflow.com/questions/1...he-main-thread

      This thread can be marked as closed.

      Comment

      Working...
      X