首先到 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里可以监控到整个文件流。
是不是很轻松,后面我会再继续写出其他的操作,欢迎大家一起交流!