ActiveMQ

1):http://baike.baidu.com/view/433374.htm 百度百科 ActiveMQ

2):
一.安裝ActiveMQ
首先去http://activemq.apache.org/download.html 下載最新版本4.1.0release (http://activemq.apache.org/activemq-410-release.html),
解壓apache-activemq-4.1-incubator.zip(或者apache-activemq-4.1-incubator.tar.gz)目錄如下:

+bin (windows下面的bat和unix/linux下面的sh)
+conf (activeMQ配置目錄,包含最基本的activeMQ配置文件)
+data (默認是空的)
+docs (index,replease版本里面沒有文檔,-.-b不知道爲啥不帶)
+example (幾個例子
+lib (activemMQ使用到的lib)
-apache-activemq-4.1-incubator.jar (ActiveMQ的binary)
-LICENSE.txt
-NOTICE.txt
-README.txt
-user-guide.html


你可以使用bin\activemq.bat(activemq) 啓動,如果一切順利,你就會看見類似下面的信息
(細節可能不一樣,比如路徑,或者jmx,jdbc信息)

ACTIVEMQ_HOME: D:\java\framework_and_lib\activemq\apache-activemq-4.1-incubator\
bin\..
Loading message broker from: xbean:activemq.xml
INFO BrokerService - ActiveMQ null JMS Message Broker (localho
st) is starting
INFO BrokerService - For help or more information please see:
http://incubator.apache.org/activemq/
INFO ManagementContext - JMX consoles can connect to service:jmx:r
mi:///jndi/rmi://localhost:1099/jmxrmi
INFO JDBCPersistenceAdapter - Database driver recognized: [apache_derby
_embedded_jdbc_driver]
INFO DefaultDatabaseLocker - Attempting to acquire the exclusive lock
to become the Master broker
INFO DefaultDatabaseLocker - Becoming the master on dataSource: org.ap
ache.derby.jdbc.EmbeddedDataSource@1d840cd
INFO JournalPersistenceAdapter - Journal Recovery Started from: Active Jou
rnal: using 5 x 20.0 Megs at: D:\java\framework_and_lib\activemq\apache-activemq
-4.1-incubator\activemq-data\journal
INFO JournalPersistenceAdapter - Journal Recovered: 0 message(s) in transa
ctions recovered.
INFO TransportServerThreadSupport - Listening for connections at: tcp://P-SUW
EI:61616
WARN MulticastDiscoveryAgent - brokerName not set
INFO TransportConnector - Connector default Started
INFO TransportServerThreadSupport - Listening for connections at: stomp://P-S
UWEI:61613
INFO TransportConnector - Connector stomp Started
INFO NetworkConnector - Network Connector default Started
INFO BrokerService - ActiveMQ JMS Message Broker (localhost, I
D:P-SUWEI-1207-1170916242296-1:0) started

*。幾個小提示
1. 這個僅僅是最基礎的ActiveMQ的配置,很多地方都沒有配置因此不要直接使用這個配置用於生產系統
2. 有的時候由於端口被佔用,導致ActiveMQ錯誤,ActiveMQ可能需要以下端口1099(JMX),61616(默認的TransportConnector)
3. 如果沒有物理網卡,或者MS的LoopBackAdpater Multicast會報一個錯誤

二. 測試你的ActiveMQ

由於ActiveMQ是一個獨立的jms provider,所以我們不需要其他任何第三方服務器就可以馬上做我們的測試了.編譯
example目錄下面的程序

ProducerTool/ConsumerTool 是JMS參考裏面提到的典型應用,Producer產生消息,Consumer消費消息
而且這個例子還可以加入參數幫助你測試剛纔啓動的本地ActiveMQ或者是遠程的ActiveMQ

ProducerTool [url] broker的地址,默認的是tcp://localhost:61616
[true|flase] 是否使用topic,默認是false
[subject] subject的名字,默認是TOOL.DEFAULT
[durabl] 是否持久化消息,默認是false
[messagecount] 發送消息數量,默認是10
[messagesize] 消息長度,默認是255
[clientID] durable爲true的時候,需要配置clientID
[timeToLive] 消息存活時間
[sleepTime] 發送消息中間的休眠時間
[transacte] 是否採用事務


ConsumerTool [url] broker的地址,默認的是tcp://localhost:61616
[true|flase] 是否使用topic,默認是false
[subject] subject的名字,默認是TOOL.DEFAULT
[durabl] 是否持久化消息,默認是false
[maxiumMessages] 接受最大消息數量,0表示不限制

[clientID] durable爲true的時候,需要配置clientID

[transacte] 是否採用事務
[sleepTime] 接受消息中間的休眠時間,默認是0,onMeesage方法不休眠
[receiveTimeOut] 接受超時

我們這樣可以使用:
java -classpath .\apache-activemq-4.1-incubator.jar;example\bin ProducerTool tcp://192.168.3.142:61616 test.mysubject
java -classpath .\apache-activemq-4.1-incubator.jar;example\bin ConsumerTool tcp://192.168.3.142:61616 test.mysubject

當然你可以使用上面的參數進行更復雜的測試,持久,事務

如果出現下面的信息,恭喜你,你的ActiveMQ已經能夠工作了

Connecting to URL: tcp://192.168.3.142:61616
Publishing a Message with size 255 to queue: TOOL.DEFAULT
Using non-durable publishing
Sleeping between publish 0 ms
Sending message: Message: 0 sent at: Thu Feb 08 15:05:34 CST 2007 ...
Sending message: Message: 1 sent at: Thu Feb 08 15:05:34 CST 2007 ...
。。。。。。。。


Connecting to URL: tcp://192.168.3.142:61616
Consuming queue: test.mysubject
Using non-durable subscription
Received: Message: 0 sent at: Thu Feb 08 14:51:34 CST 2007 ...
Received: Message: 1 sent at: Thu Feb 08 14:51:34 CST 2007 ...
。。。。


三.小結

我們已經下載,啓動,並且用程序測試了我們的ActiveMQ,而後面將在這個能跑得ActiveMQ進一步的走下去,一步一步展示ActiveMQ的高級特性。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章