Start and Stop JMS Listener using Spring

后端 未结 3 1385
半阙折子戏
半阙折子戏 2020-12-16 23:35

So question is how to temporary stop and start a jms listener created using spring using the fallowing way :



        
相关标签:
3条回答
  • 2020-12-16 23:47

    You can assign an id to the listener-container. Then get a reference to it, either by calling getBean or getting it injected. This will give you a AbstractJmsListeningContainer on which you can call start / stop.

    0 讨论(0)
  • 2020-12-16 23:56

    You can also get a hold of the messageListenerContainer, and invoke stop() on it:

    @javax.annotation.Resource //autowire by name
     private AbstractJmsListeningContainer myMessageListenerContainer;
    
     myMessageListenerContainer.stop();
    
     I'm using the more verbose setup of this container:
     <bean id="myMessageListenerContainer" class="org.springframework.jms.listener.DefaultMes sageListenerContainer">
     <property name="connectionFactory" ref="jmsConnectionFactory"/>
     <property name="destination" ref="myQueue"/>
     <property name="messageListener" ref="myListener"/>
     <property name="autoStartup" value="true" />
     </bean>
    

    Here you see that you can set autoStartup to false if you don't want the listenerContainer to automatically start.

    0 讨论(0)
  • 2020-12-16 23:59

    Yes thats do the trick.

    <jms:listener-container concurrency="1" connection-factory="exampleJmsFactory"  destination-type="queue" message-converter="exampleMessageConverter">
            <jms:listener id="exampleProductsMessageListener" destination="incoming.example.client.queue" ref="exampleProductsMessageConsumer" method="consume"/>
    </jms:listener-container>
    
    
    
    DefaultMessageListenerContainer exampleProductsMessageListener= Registry.getApplicationContext().getBean("exampleProductsMessageListener", DefaultMessageListenerContainer.class);
    exampleProductsMessageListener.stop();
    
    0 讨论(0)
提交回复
热议问题