首先到 http://mule.codehaus.org/ 網站下載mule解壓安裝到本地硬盤,例如E:\java\mule-1.3-rc2
其次我們在這個目錄下創建一個目錄testmule用於測試
然後我們在testmule下創建如下目錄
src :存放源文件
classes:存放java class文件
conf:存放xml配置文件
bin:存放測試執行的批處理(*.bat)文件
1、通用環境的搭建
以爲爲監聽程序服務的接口和實現
Test.java
package org.lyj.mule;
public interface Test {
public void echo(String name);
}
Service.java
package org.lyj.mule;
public class Service implements Test {
public void echo(String name) {
System.out.println("called="+name);
}
}
從mule的sample下的任意一個例子的conf裏把 log4j.properties 複製到 testmule/conf下,其中的內容如下
#Mule default logging configuration
#Logs to stdout and file. the log file is called mule.log and is stored in the directory
#that the mule server is executed in
log4j.rootCategory=error, stdout, file
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p %d [%t] %c: %m%n
# Maintain alog file with a single file backup
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=mule.log
log4j.appender.file.MaxFileSize=10MB
# Keep one backup file
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%-5p %d [%t] %c: %m%n
#You can set custom log levels per package here
log4j.logger.org.apache=WARN
#Switch to info to see Test suite lifecycle info
log4j.logger.org.mule.tck=WARN
2、File Provider的實現
在conf下新建一個配置文件 test-file-config.xml,內容如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mule-configuration PUBLIC "-//SymphonySoft //DTD mule-configuration XML V1.0//EN"
"http://www.symphonysoft.com/dtds/mule/mule-configuration.dtd">
<mule-configuration id="file" version="1.0">
<description>
本測試由劉玉軍完整測試,如果有問題請訪問http://blog.csdn.net/lyj_china
</description>
<model name="test file">
<mule-descriptor name="Service1" implementation="org.lyj.mule.Service">
<inbound-router>
<endpoint address="file:///D:/temp/">
<properties>
<property name="pollingFrequency" value="30000"/>
<property name="moveToDirectory" value="/D:/done"/>
</properties>
</endpoint>
</inbound-router>
</mule-descriptor>
</model>
</mule-configuration>
意思就是每隔30秒把文件從 d:/temp下移動到d:/done目錄下
在bin下面創建文件 testfile.bat,內容如下:
@echo off
REM There is no need to call this if you set the MULE_HOME in your environment properties
if "%MULE_HOME%" == "" SET MULE_HOME=..\..
REM Set your application specific classpath like this
SET CLASSPATH=%MULE_HOME%\testmule\conf;%MULE_HOME%\testmule\classes;
call %MULE_HOME%\bin\mule.bat -config ../conf/test-file-config.xml
SET MULE_MAIN=
SET CLASSPATH=
然後我們運行testfile.bat 啓動,正常啓動mule後,就可以定時把 temp目錄下的文件複製到done下了。
並且在mule運行界面會打印出文件的內容,也就是說我們在mule裏可以監控到整個文件流。
實戰mule(1)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.