本章我們通過一個簡單的實例來介紹如何使用camel。
這個實例中,我們會把文件從目錄camel/input 移動到camel/output.為了方便我們跟蹤哪些文件被移動,我們會記錄日志。
這個實例中,我們會把文件從目錄camel/input 移動到camel/output.為了方便我們跟蹤哪些文件被移動,我們會記錄日志。
1、創建一個xml
在 ServiceMix中定義一個新的 route,最簡單的方式之一就是定義一個Blueprint XML file,就像下邊一樣:
2.部署
我們只需要將第一步創建的xml復制到serviceMix下的 deploy 目錄,就會被serviceMix 識別并部署。你會看到被放到目錄camel/input下的文件被
移動到camel/output,如果你使用log:display命令,會看到文件移動的日志:
3. 使用命令行管理 route
使用osgi:list,你會看到剛才我們部署的bundle
你會看到我們剛才部署的bundle ID是221,我們可以通過這個bundle ID來啟動或者關閉bundle
在 ServiceMix中定義一個新的 route,最簡單的方式之一就是定義一個Blueprint XML file,就像下邊一樣:
<?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:camel/input"/>
<log message="Moving ${file:name} to the output directory"/>
<to uri="file:camel/output"/>
</route>
</camelContext>
</blueprint>
2.部署
我們只需要將第一步創建的xml復制到serviceMix下的 deploy 目錄,就會被serviceMix 識別并部署。你會看到被放到目錄camel/input下的文件被
移動到camel/output,如果你使用log:display命令,會看到文件移動的日志:
2015-04-09 17:10:19,515 | INFO | le://camel/input | route1
| ? ? | 116 - org.apache.camel.camel-cor
e - 2.14.1 | Moving test.xml.bak to the output directory
3. 使用命令行管理 route
使用osgi:list,你會看到剛才我們部署的bundle
[ 221] [Active ] [Created ] [ ] [ 80] test.xml (0.0.0)
karaf@root> osgi:stop 221
karaf@root> osgi:start 221