Camel实现FTP下载

FTP路径有存在日期文件夹,且世界时、北京时混合

public void threadFTP(ExecutorService cachedThreadPool) {

        cachedThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                CamelContext context = new DefaultCamelContext();
                try {
                    context.addRoutes(new RouteBuilder() {
                        @Override
                        public void configure() throws Exception {
                            String day = DateUtils.buildNowStr(DateUtils.DAY_FORMAT);
                            IdempotentRepository<String> ir = FileIdempotentRepository.fileIdempotentRepository(new File("target/fire.dat"), 250, 512000);
                            //二进制传输、处理后不移动文件、递归处理目录、被动模式、目录轮询1分钟、如果文件已存在忽略
                            from("ftp://xxx:xxx@xxx/ShanDong/"+day+"/Fire_Result?binary=true&noop=true&recursive=true&passiveMode=true&useFixedDelay=true&delay=60000&idempotent=true")
                            .idempotentConsumer(header("CamelFileName"), ir)
                            .to("?fileExist=Ignore&tempFileName=fire.tmp"+day+"?fileExist=Ignore")
                            .log(LoggingLevel.INFO, logger, "Downloaded FTP-Fire file ${file:name} complete.");
                        }
                    });
                    context.start();
                    Thread.sleep(24*60*60*1000);
                    context.stop();
                } catch (Exception e) {
                    logger.info("exception-------------"+e);
                }
            }
        });
    }
ExecutorService cachedThreadPool = Executors.newCachedThreadPool();

    @Scheduled(cron="0 0 0 * * ?")
    private void downftp() throws InterruptedException {
        new FileCopierThread().threadFTP(cachedThreadPool);
        Thread.sleep(10000);
        int threadCount = ((ThreadPoolExecutor)cachedThreadPool).getActiveCount();
    }

    @PostConstruct 
    public void initMethod() throws Exception {  
        new FileCopierThread().threadFTP(cachedThreadPool);
    }

猜你喜欢

转载自blog.csdn.net/jiangshuanshuan/article/details/80134714
今日推荐