ACTIVEMQ遇到的坑与经验

经验:

1、后台启动   nohup ./activemq start > /usr/local/apache-activemq-5.2.0/data/run.log 2>&1 &
2、本地测试速度,topic,单生产者,单线程生产速度2w-3w/s ,消费者单消费者,单线程消费速度为1W-2W/s ,比生产者速度慢。
3、topic主题式,每个消费者消费从连接MQ之后的全部消息。
4、MQ配置文件中可以控制topic预留的消息数量,控制慢消费相关的配置(更多说明

		<policyMap>
              <policyEntries>
                <policyEntry topic=">" >
                    <!-- The constantPendingMessageLimitStrategy is used to prevent
                         slow topic consumers to block producers and affect other consumers
                         by limiting the number of messages that are retained
                         For more information, see:

                         http://activemq.apache.org/slow-consumer-handling.html

                    -->
                  <pendingMessageLimitStrategy>
                    <constantPendingMessageLimitStrategy limit="1000"/>
                  </pendingMessageLimitStrategy>
				 
				  <subscriptionRecoveryPolicy>
					<timedSubscriptionRecoveryPolicy recoverDuration="10000" />
				  </subscriptionRecoveryPolicy>
				 
                </policyEntry>
				<policyEntry topic=">" gcInactiveDestinations="true" inactiveTimoutBeforeGC="10000"/>
              </policyEntries>
         </policyMap>



坑:

1、主题式(topic) 非持久化模式的生产消费者,会出现内存爆满,内存溢出,cpu居高不下问题

后知:无限创建生产者,没有关闭,导致服务器不GC。正常使用方法,创建一个生产者,绑定工作线程,不要频繁创建关闭生产者,一般情况下可以用一个connection                         一个session,一个producer。

         生产者创建过程:

 用链接工厂创建ActiveMq链接

         从connection中获取session(事物或者非事物)

         从session获取主题

         从session根据主题获取生产者

		ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
		connection = factory.createConnection();
		connection.start();
		session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
		topic = session.createTopic("qq.mq.topic");
		//		topic = session.createTopic("qq.mq.topic");
		producer = session.createProducer(topic);
		producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);


坑后经验:远程问题挪到本地,内存溢出通过jVisualVM查看内存GC问题,不断调整代码,查看服务器的反映,没事看看,觉得没问题的代码,或者比对一下





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章