SarahDeng
asked on
How to start/stop ActiveMQ listener programatically?
Hi Experts,
I have ActiveMQ 5.4 and Spring3.1. This MessageListener will be kicked off once there is a message dropped in the queue. Because this MessageListener will insert a large amount of data, I wonder if there is a way to stop this Listener, and restart it once the a large amount of data inserted into DB.
How to stop/restart the listener programatically? Thanks!
public class ExampleListener implements MessageListener {
public void onMessage(Message message) {
insert a LARGE amount of data into DB table using Hibernate.
I
}
}
This is Spring ApplicationContext.xml
<bean id="destination" class="org.apache.activemq .command.A ctiveMQQue ue">
<constructor-arg>
<value>HelloWorldQueue</va lue>
</constructor-arg>
</bean>
<bean id="jmsFactory" class="org.apache.activemq .pool.Pool edConnecti onFactory" destroy-method="stop">
<property name="connectionFactory">
<bean class="org.apache.activemq .ActiveMQC onnectionF actory">
<property name="brokerURL">
<value>tcp://localhost:616 16</value>
</property>
</bean>
</property>
</bean>
<bean id="myJmsTemplate" class="org.springframework .jms.core. JmsTemplat e">
<property name="connectionFactory" ref="jmsFactory"/>
</bean>
<!-- this is the Message Driven POJO (MDP) -->
<bean id="messageListener" class="com.sprint.cto.sp.h elloworld. ExampleLis tener" />
<!-- and this is the message listener container -->
<bean id="jmsContainer"
class="org.springframework .jms.liste ner.Defaul tMessageLi stenerCont ainer">
<property name="connectionFactory" ref="jmsFactory"/>
<property name="destination" ref="destination"/>
<property name="messageListener" ref="messageListener" />
</bean>
I have ActiveMQ 5.4 and Spring3.1. This MessageListener will be kicked off once there is a message dropped in the queue. Because this MessageListener will insert a large amount of data, I wonder if there is a way to stop this Listener, and restart it once the a large amount of data inserted into DB.
How to stop/restart the listener programatically? Thanks!
public class ExampleListener implements MessageListener {
public void onMessage(Message message) {
insert a LARGE amount of data into DB table using Hibernate.
I
}
}
This is Spring ApplicationContext.xml
<bean id="destination" class="org.apache.activemq
<constructor-arg>
<value>HelloWorldQueue</va
</constructor-arg>
</bean>
<bean id="jmsFactory" class="org.apache.activemq
<property name="connectionFactory">
<bean class="org.apache.activemq
<property name="brokerURL">
<value>tcp://localhost:616
</property>
</bean>
</property>
</bean>
<bean id="myJmsTemplate" class="org.springframework
<property name="connectionFactory" ref="jmsFactory"/>
</bean>
<!-- this is the Message Driven POJO (MDP) -->
<bean id="messageListener" class="com.sprint.cto.sp.h
<!-- and this is the message listener container -->
<bean id="jmsContainer"
class="org.springframework
<property name="connectionFactory" ref="jmsFactory"/>
<property name="destination" ref="destination"/>
<property name="messageListener" ref="messageListener" />
</bean>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! The question is well answered!
ajaycv,
I want to learn more about how to stop/restart DMLC, do you have any example I can use? Thanks!
ajaycv,
I want to learn more about how to stop/restart DMLC, do you have any example I can use? Thanks!
ASKER
Do I need to configure "DefaultMessageListenerCon tainer " or other connectionFactory as such to work well in the use case (it would insert a large data into DB, it takes a longer time to finish)? There is Another message Listener listens to another queue will remove some records from this SAME table.
If I use the default configuration I may get timeout or exception in this case.
Please comment.
If I use the default configuration I may get timeout or exception in this case.
Please comment.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!!
The DefaultMessageListenerCont
http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/jms/listener/DefaultMessageListenerContainer.html