简体   繁体   English

如何使用apache camel复制文件

[英]How to copy files using apache camel

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class ReadFileExample {
public static void main(String [] args) throws Exception{
    System.out.println("trying to copy file");
    CamelContext ctx = new DefaultCamelContext();
    RouteBuilder route = new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("file://Users/aranja2/Documents/in/?fileName=sample.txt&charset=utf-8")
             .to("file://Users/aranja2/Documents/out/?fileName=sample.txt&charset=utf-8");
        }
    };
    ctx.addRoutes(route);
    ctx.start();
    // Maybe sleep a little here
    // Thread.sleep(4000);
    ctx.stop();
 }
}

I am using camel to copy files but it is not happening.I am using mac. 我正在使用骆驼来复制文件,但它没有发生。我正在使用mac。 The messages thrown are 抛出的消息是

[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.16.2 (CamelContext: camel-1) is starting [main] INFO org.apache.camel.management.ManagedManagementStrategy - JMX is enabled [main] INFO org.apache.camel.impl.converter.DefaultTypeConverter - Loaded 183 type converters [main] INFO org.apache.camel.impl.DefaultRuntimeEndpointRegistry - Runtime endpoint registry is in extended mode gathering usage statistics of all incoming and outgoing endpoints (cache limit: 1000) [main] INFO org.apache.camel.impl.DefaultCamelContext - AllowUseOriginalMessage is enabled. [主要] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.16.2(CamelContext:camel-1)正在启动[main] INFO org.apache.camel.management.ManagedManagementStrategy - JMX已启用[main] INFO org .apache.camel.impl.converter.DefaultTypeConverter - 已加载183类型转换器[main] INFO org.apache.camel.impl.DefaultRuntimeEndpointRegistry - 运行时端点注册表处于扩展模式,收集所有传入和传出端点的使用情况统计信息(缓存限制:1000 )[main] INFO org.apache.camel.impl.DefaultCamelContext - 启用AllowUseOriginalMessage。 If access to the original message is not needed, then its recommended to turn this option off as it may improve performance. 如果不需要访问原始邮件,则建议关闭此选项,因为它可能会提高性能。 [main] INFO org.apache.camel.impl.DefaultCamelContext - StreamCaching is not in use. [main] INFO org.apache.camel.impl.DefaultCamelContext - StreamCaching未使用。 If using streams then its recommended to enable stream caching. 如果使用流,则建议启用流缓存。 See more details at http://camel.apache.org/stream-caching.html [main] INFO org.apache.camel.component.file.FileEndpoint - Endpoint is configured with noop=true so forcing endpoint to be idempotent as well [main] INFO org.apache.camel.component.file.FileEndpoint - Using default memory based idempotent repository with cache max size: 1000 [main] INFO org.apache.camel.impl.DefaultCamelContext - Route: route1 started and consuming from: Endpoint[file://Users/aranja2/Documents/in/?noop=true] [main] INFO org.apache.camel.impl.DefaultCamelContext - Total 1 routes, of which 1 is started. 有关更多详细信息,请访问http://camel.apache.org/stream-caching.html [main] INFO org.apache.camel.component.file.FileEndpoint - 端点配置为noop = true,因此强制端点也是幂等的[main] INFO org.apache.camel.component.file.FileEndpoint - 使用基于默认内存的幂等存储库和缓存最大大小:1000 [main] INFO org.apache.camel.impl.DefaultCamelContext - 路由:route1已启动并消耗来自:端点[file:// Users / aranja2 / Documents / in /?noop = true] [main] INFO org.apache.camel.impl.DefaultCamelContext - 总共1条路由,其中​​1条已启动。 [main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.16.2 (CamelContext: camel-1) started in 0.344 seconds [main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.16.2 (CamelContext: camel-1) is shutting down [main] INFO org.apache.camel.impl.DefaultShutdownStrategy - Starting to graceful shutdown 1 routes (timeout 300 seconds) [Camel (camel-1) thread #1 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Route: route1 shutdown complete, was consuming from: Endpoint[file://Users/aranja2/Documents/in/?noop=true] [main] INFO org.apache.camel.impl.DefaultShutdownStrategy - Graceful shutdown of 1 routes completed in 0 seconds [main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.16.2 (CamelContext: camel-1) uptime 0.359 seconds [main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.16.2 (CamelContext: camel-1) is shutdown in 0.007 seconds [主要] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.16.2(CamelContext:camel-1)在0.344秒内启动[主要] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.16.2( CamelContext:camel-1)正在关闭[main] INFO org.apache.camel.impl.DefaultShutdownStrategy - 开始正常关闭1个路由(超时300秒)[Camel(camel-1)线程#1 - ShutdownTask] INFO组织。 apache.camel.impl.DefaultShutdownStrategy - 路由:route1 shutdown complete,正在使用:Endpoint [file:// Users / aranja2 / Documents / in /?noop = true] [main] INFO org.apache.camel.impl.DefaultShutdownStrategy - 在0秒内完成1条路线的正常关闭[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.16.2(CamelContext:camel-1)正常运行时间0.359秒[主要] INFO org.apache.camel.impl .DefaultCamelContext - Apache Camel 2.16.2(CamelContext:camel-1)在0.007秒内关闭

are you sure you are reaching that directory on //Users/aranja2/Documents/in/?fileName=sample.txt? 你确定你到达//Users/aranja2/Documents/in/?fileName=sample.txt上的那个目录吗? You rout seems ok. 你溃败似乎没问题。 I've attached a sample project with a route copying from one directory to another. 我附加了一个示例项目,其中路径从一个目录复制到另一个目录。 This ruse use the same parameter fileName as yours. 此ruse使用与您相同的参数fileName You can run it just it mvn camel:run 你可以运行它mvn camel:run

https://drive.google.com/file/d/0B9AooXd3hwFyWjZ4aEFRc0Znam8/view?usp=sharing https://drive.google.com/file/d/0B9AooXd3hwFyWjZ4aEFRc0Znam8/view?usp=sharing

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM