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問題,不斷調整代碼,查看服務器的反映,沒事看看,覺得沒問題的代碼,或者比對一下





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