Posted on 2015-04-10 15:37
xiaolang 閱讀(5170)
評論(0) 編輯 收藏
在本章我們介紹在serviceMIx 中圖和使用 ActiveMQ、features命令,入門的3篇文章來自
http://servicemix.apache.org/docs/5.0.x/quickstart/index.html,有興趣的可以再去看看英文的。
ActiveMQ
每個Apache ServiceMix的實例是一個嵌入式activemq jms代理,這樣可以很方便的在同一臺機器上使用持久消息來通信,
但是它也支持集群和負載均衡。
在這個實例中,我們依然像上個例子一樣,在2個目錄中移動文件,把記錄日志的部分改為發(fā)送一條jms消息到消息隊列,
然后再創(chuàng)建一個新的route來接受事件并記錄日志:
?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="file:activemq/input"/>
<to uri="file:activemq/output"/>
<setBody>
<simple>
FileMovedEvent(file: ${file:name}, timestamp: ${date:now:hh:MM:ss.SSS})
</simple>
</setBody>
<to uri="activemq://events" />
</route>
</camelContext>
</blueprint>
保存這個文件,并且放到serviceMix的deploy目錄,會看到復制到 activemq/input 目錄中的文件被復制到 activemq/output
接受消息
在第一個文件中,除了復制文件,你看不到任何的log記錄。它發(fā)送了jms消息,但是沒有接受者,我們可以創(chuàng)建一個route來接受消息:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="activemq://events"/>
<to uri="log:events"/>
</route>
</camelContext>
</blueprint>
你可以通過log:display來查看日志消息。你可以通過osgi:start 和 osgi:stop來啟動和關閉這個bundle.當你重啟完第一個bundle后,你收到所有文件移動后發(fā)出
的消息事件。
features命令
karaf@root> features:list | grep camel
[uninstalled] [5.4.0 ] examples-activiti-camel servicemix-examples-5.4.0
[uninstalled] [5.4.0 ] examples-akka-camel servicemix-examples-5.4.0
karaf@root> features:install webconsolekaraf@root> features:list | grep webconsole
[installed ] [2.4.1 ] webconsole karaf-2
.4.1 Karaf WebConsole for administration and monitoring
通過features:install webconsole可以安裝 webconsole bundle,成功后你可以通過 http://localhost:8181/system/console 用戶名密碼:smx/smx來
登錄,可以通過瀏覽器來上傳、啟動,停止bundle。