# Apache Camel组件之FileComponent **Repository Path**: lsjkclyc/camel ## Basic Information - **Project Name**: Apache Camel组件之FileComponent - **Description**: Apache Camel主要提供了以下功能: 1,实现了EIP的大部分模式,如果你要在不同的应用系统之间以不同的方式传递消息,那么你可以从Apache Camel中找到解决反感。 2,提供了大量Component(组件),每个组件都是一种消息中间件(或消息服务)的具体实现,每个消息中间件所用的协议都是不同的,因此,你可以通过多种不同的协议来完成消息传输。(http、tcp、ftp、kafka等消息可以互相转换、编排 传输) 3,允许用户定义灵活的路由规则,从这个角度来说,Apache Camel是一个规则引擎。 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2020-05-24 - **Last Updated**: 2023-01-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Apache Camel组件之FileComponent 参考官网:https://camel.apache.org/components/latest/index.html #### 介绍 Apache Camel主要提供了以下功能: 1,实现了EIP的大部分模式,如果你要在不同的应用系统之间以不同的方式传递消息,那么你可以从Apache Camel中找到解决。 2,提供了大量Component(组件),每个组件都是一种消息中间件(或消息服务)的具体实现,每个消息中间件所用的协议都是不同的,因此,你可以通过多种不同的协议来完成消息传输。(http、tcp、ftp、kafka等消息可以互相转换、编排 传输) 3,允许用户定义灵活的路由规则,从这个角度来说,Apache Camel是一个规则引擎。 Camel之File组件(参考https://camel.apache.org/components/latest/index.html) maven 下 camel集成spring 1、pom中引入 log4j log4j 1.2.17 org.apache.camel camel-core 3.2.0 org.apache.camel camel-spring 3.2.0 org.apache.logging.log4j log4j-core 2.12.1 2、配置camel插件 org.apache.camel camel-maven-plugin META-INF/spring/ 3、在/src/main/resources下新建application.xml log4j.properties log4j.rootLogger = debug,stdout ### \u8F93\u51FA\u4FE1\u606F\u5230\u63A7\u5236\u62AC ### log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target = System.out log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n 4、新建App public class App { public static void main( String[] args ) throws InterruptedException { ApplicationContext ac = new ClassPathXmlApplicationContext("application.xml"); new Thread(new Runnable() { @Override public void run() { try { //写文件时间长,模拟从另一个地方同步过来,大文件同步到目标文件夹中,如果文件比较大,这时,定时任务开始同步,那么就会锁定文件,直到该文件移动(写完)完,才会同步走 String content = "a dog will be write in file"; File file = new File("D:\\tmp\\ff.done"); if(!file.exists()){ file.createNewFile(); } FileWriter fileWriter = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fileWriter); content=content+" ----- "; bw.write(content+"\n"); Thread.sleep(2000); bw.flush(); bw.close(); System.out.println("finish"); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); while (true) { Thread.sleep(10000); } } }