时间:2007-11-07 关键字: spring2.0 activemq4.1.1
(1)spring配置文件
<bean id="queueConnectionFactory"
class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://192.168.18.77:61616"/>
<property name="useAsyncSend" value="true"/>
</bean>
<bean id="topicSendConnectionFactory"
class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://192.168.18.77:61617"/>
<property name="useAsyncSend" value="true"/>
</bean>
<bean id="topicListenConnectionFactory"
class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://192.168.18.77:61617"/>
<property name="clientID" value="clientId_001"/>
</bean>
<!-- 消息队列监听者(MDP) -->
<bean id="queueMsgListener" class="com.cdmcs.oa.jms.MagMessageListener"/>
<!-- 消息主题监听者(MDP) -->
<bean id="topicMsgListener" class="com.cdmcs.oa.jms.MagTopicMsgListener"/>
<!--定义消息队列-->
<bean id="myQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="CQSJOA.001"/>
</bean>
<!--定义订阅主题-->
<bean id="myTopic" class="org.apache.activemq.command.ActiveMQTopic">
<constructor-arg value="basicInfo.topic"/>
</bean>
<!-- 监听自己的消息 -->
<bean id="myMsgQueuelistenerContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="queueConnectionFactory" />
<property name="concurrentConsumers" value="5"/>
<property name="destination" ref="myQueue"/>
<property name="messageListener" ref="queueMsgListener"/>
<property name="receiveTimeout" value="10000"/>
<property name="sessionTransacted" value="true"/>
<property name="sessionAcknowledgeModeName" value="CLIENT_ACKNOWLEDGE"/>
</bean>
<!--监听公共消息(持久订阅者)-->
<bean id="myMsgTopicListenerContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="topicListenConnectionFactory"/>
<property name="pubSubDomain" value="true"/>
<property name="concurrentConsumers" value="1"/>
<property name="receiveTimeout" value="10000"/>
<property name="destination" ref="myTopic" />
<property name="sessionAcknowledgeModeName" value="CLIENT_ACKNOWLEDGE"/>
<property name="subscriptionDurable" value="true"/>
<property name="clientId" value="clientId_001"/>
<property name="durableSubscriptionName" value="clientId_001"/>
<property name="messageListener" ref="topicMsgListener" />
</bean>
<bean id="jmsQueueTemplate"
class="org.springframework.jms.core.JmsTemplate102">
<property name="connectionFactory" ref="queueConnectionFactory"/>
<property name="messageConverter" ref="simpleConverter"/>
<property name="sessionTransacted" value="true"/>
<property name="receiveTimeout" value="10000"/>
</bean>
<bean id="jmsTopicTemplate"
class="org.springframework.jms.core.JmsTemplate102">
<property name="connectionFactory" ref="topicSendConnectionFactory"/>
<property name="messageConverter" ref="simpleConverter"/>
<property name="pubSubDomain" value="true"/>
<property name="sessionTransacted" value="true"/>
<property name="receiveTimeout" value="10000"/>
</bean>
<bean id="simpleConverter"
class="org.springframework.jms.support.converter.SimpleMessageConverter" />
(2)activemq配置
<transportConnector name="openwire" uri="tcp://localhost:61616"/>
<transportConnector name="myTopic" uri="tcp://localhost:61617"/>
(3)问题
If some subscriber is offline long time,there are many topic messages in DB(3000to4000).the activemq is very slowly,at last it can't listen to myTopic and throw the exception like this:
: java.lang.OutOfMemoryError: Java heap space
A:activemq.xml
<memoryManager>
<usageManager id="memory-manager" limit="20 MB"/>
</memoryManager>
B:wraper.conf
# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3
# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=256M
C:activemq.bat
ACTIVEMQ_OPTS="-Xms512m -Xmx1000M -Dorg.apache.activemq.UseDedicatedTaskRunner=true -Dderby.system.home=${ACTIVEMQ_BASE}/data -Dderby.storage.fileSyncTransactionLog=true"