Apache Camel继承Spring Boot 实现文件远程复制和转移
pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-ftp</artifactId>
<version>2.18.0</version>
</dependency>
URI的格式
ftp://[username@]hostname[:port]/directoryname[?options]
sftp://[username@]hostname[:port]/directoryname[?options]
ftps://[username@]hostname[:port]/directoryname[?options]
如果未提供端口号,Camel将根据协议提供默认值(ftp = 21,sftp = 22,ftps = 2222)。
例:
ftp://173.5.206.53:2121/MHE/?username=ftpAdmin&password=123456&binary=true&passiveMode=true&delete=true&delay=60000 注:ftp的路径必须是 当前ip:端口 + 当前账号密码登陆进去的目录往下走(不能往上走,没权限),路径才会生效,否则不会报错,也不会进行文件操作
配置文件信息:
#文件压缩本地地址(备份)
ftp.local.backups.dir=file:D:/gz/backups?move=delete&delay=30s
#大数据服务器地址(备份)
ftp.bigdata.backups.adress=sftp://218.984.130.146:51268/../apps/chinamobile/bigdata/dataConsistencyRepair/backups/?username=root&password=Redoor2018@net123&delay=30s #大数据服务器修复地址(运维存放文件夹,使用后存放到备份文件中)
ftp.bigdatarepair.adress=sftp://218.984.130.146:51268/../apps/chinamobile/bigdata/bigdatarepair/?username=root&password=Redoor2018@net123&move=/apps/chinamobile/bigdata/bigdatarepair/backups&delay=30s
#本地文件修复地址(复制到自定义文件夹)
ftp.local.repair=file:D:/localrepair #对比大数据差异文件存放地址(通知运维)
ftp.bigdatadifference.adress=sftp://218.984.130.146:51268/../apps/chinamobile/bigdata/difference/?username=root&password=Redoor2018@net123&delay=30s camel.springboot.main-run-controller=true
文件实现文件复制,转移:
/**
* 远程文件监听和拉取
*/
@Component
public class DownLoadRouteBuilder extends RouteBuilder{ private Logger log = Logger.getLogger(DownLoadRouteBuilder.class); /**
* 文件压缩本地地址
*/
@Value("${ftp.local.dir}")
private String localFileDir; /**
* 大数据服务器地址
*/
@Value("${ftp.bigdata.adress}")
private String bigDataServer; /**
* 文件压缩本地地址(上传备份)
*/
@Value("${ftp.local.backups.dir}")
private String localFileDirBackups; /**
* 大数据服务器地址(上传备份)
*/
@Value("${ftp.bigdata.backups.adress}")
private String bigDataBackupsServer; /**
* 本地文件修复地址
*/
@Value("${ftp.local.repair}")
private String localRepair;
/**
* 大数据服务器修复地址
*/
@Value("${ftp.bigdatarepair.adress}")
private String bigDataRepairServer; /**
* 对比大数据差异文件存放地址
*/
@Value("${ftp.bigdatadifference.adress}")
private String bigdatadifference; @Override
public void configure() throws Exception {
//文件上传大数据
from(localFileDir).to(bigDataServer).process("transferDataProcessToBigData");
//文件上传大数据(上传备份) 备份文件不存redis有一份就好
from(localFileDirBackups).to(bigDataBackupsServer).process("transferDataProcessToBigData"); //修复文件拉取
from(bigDataRepairServer).to(localRepair).process("transferDataProcessBigDataRepairToLocal");
//对比大数据差异文件存放地址
from(bigdatadifference).to(bigdatadifference).process("transferDataProcessToBigDataDifference"); System.out.println("file download ok...");
log.info("远程文件监听和拉取 已启动.......");
} }
文件复制获取信息:
文件远程复制和移动以后,本对象中可以显示
文件一:
/**
* 监听本地修复文件
*/
@Component
public class TransferDataProcessBigDataRepairToLocal implements Processor{ private Logger log = Logger.getLogger(TransferDataProcessBigDataRepairToLocal.class); @Autowired
private RepairRedisUtil repairRedisUtil;
/**
* 本地文件修复地址
*/
@Value("${ftp.local.repair}")
private String localRepair; /**
* redis工具类
*/
@Autowired
RedisUtils redisUtils; /**
* 读取GZ压缩文件,多线程
*/
@Autowired
AsyncService asyncService; @Override
public void process(Exchange exchange) throws Exception {
GenericFileMessage<RandomAccessFile> inFileMessage = (GenericFileMessage<RandomAccessFile>) exchange.getIn();
String fileName = inFileMessage.getGenericFile().getFileName();//文件名
String splitTag = File.separator;//系统文件分隔符
String absolutePath = localRepair + splitTag + fileName;
System.out.println(absolutePath);//文件的绝对路径
System.out.println("read file and push to falcon..."); System.out.println("准备修复文件!");
//文件的绝对路径去掉:file:
String filePath = absolutePath.substring(absolutePath.indexOf("file:")+"file:".length()); //创建redisKey 项目名称,模块名称,功能名称,自定义名称
String bigdatarepair = redisUtils.buildRedisKey("OneLink","DataConsistencyRepair","bigdatarepair","list"); //文件名称解析并进行redis缓存
DataRepairCacheModel dataRepairModel = repairRedisUtil.getFileInfo(fileName);
//获取缓存key
String cacheKey = repairRedisUtil.getDataRepairCacheKey(dataRepairModel.getBusinessCode());
//文件名称缓存
repairRedisUtil.CacheRepairData(cacheKey,dataRepairModel,0); }
}
文件二:
/**
* 监听大数据服务器是否上传成功
*/
@Component
public class TransferDataProcessToBigData implements Processor{ private Logger log = Logger.getLogger(TransferDataProcessToBigData.class); /**
* redis工具类
*/
@Autowired
RedisUtils redisUtils; /**
* 大数据服务器地址
*/
@Value("${ftp.bigdata.adress}")
private String bigDataServer; @Override
public void process(Exchange exchange) throws Exception {
GenericFileMessage<RandomAccessFile> inFileMessage = (GenericFileMessage<RandomAccessFile>) exchange.getIn();
String fileName = inFileMessage.getGenericFile().getFileName();//文件名
String splitTag = File.separator;//系统文件分隔符
System.out.println(bigDataServer + splitTag + fileName);//文件的绝对路径
System.out.println("read file and push to falcon..."); //添加:判断redis是否存在,不存在就删除,存在就不管 //创建redisKey 项目名称,模块名称,功能名称,自定义名称
String redisName = redisUtils.buildRedisKey("OneLink","DataConsistencyRepair","upload","List");
//获取
Map<String, DataUploadModel> stringObjectMap = (Map<String, DataUploadModel>) JSON.parseObject((String)redisUtils.get(redisName),Map.class); //删除
stringObjectMap.remove(fileName); //将集合存入缓存中
redisUtils.set(redisName, JSONObject.toJSONString(stringObjectMap)); log.info("文件信息:"+fileName+"上传大数据服务器成功!");
log.info("文件信息:"+fileName+"从redis删除标记!");
}
}
文件三:
/**
* 对比大数据差异文件存放地址监听
*/
@Component
public class TransferDataProcessToBigDataDifference implements Processor{ private Logger log = Logger.getLogger(TransferDataProcessToBigDataDifference.class); /**
* redis工具类
*/
@Autowired
RedisUtils redisUtils;
@Autowired
private Task task; /**
* 对比大数据差异文件存放地址
*/
@Value("${ftp.bigdatadifference.adress}")
private String bigdatadifference; @Override
public void process(Exchange exchange) throws Exception {
GenericFileMessage<RandomAccessFile> inFileMessage = (GenericFileMessage<RandomAccessFile>) exchange.getIn();
String fileName = inFileMessage.getGenericFile().getFileName();//文件名
String splitTag = File.separator;//系统文件分隔符
System.out.println(bigdatadifference + splitTag + fileName);//文件的绝对路径
System.out.println("read file and push to falcon...");
task.send();
System.out.println("给运维发送邮件!");
}
}
官方API文档:http://camel.apache.org/ftp2.html
Apache Camel继承Spring Boot 实现文件远程复制和转移的更多相关文章
- Apache Camel 与 Spring Boot 集成,通过FTP定时采集、处理文件 (转)
1.概要: 本项目主要是通过在Spring平台上配置Camel.FTP,实现定时从FTP服务器下载文件到本地.解析文件.存入数据库等功能. 2.搭建空项目: Spring Boot有几种自动生成空项目 ...
- Apache Camel,Spring Boot 实现文件复制,转移 (转)
基本框架 Apache Camel Spring Boot Maven 开发过程 1.新建一个POM(quickstart)项目,在POM文件中添加Camel和Spring Boot的依赖 <p ...
- Spring Boot入门——文件上传与下载
1.在pom.xml文件中添加依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="ht ...
- 51. spring boot属性文件之多环境配置【从零开始学Spring Boot】
原本这个章节是要介绍<log4j多环境不同日志级别的控制的>但是没有这篇文章做基础的话,学习起来还是有点难度的,所以我们先一起了解下spring boot属性文件之多环境配置,当然文章中也 ...
- spring boot:单文件上传/多文件上传/表单中多个文件域上传(spring boot 2.3.2)
一,表单中有多个文件域时如何实现说明和文件的对应? 1,说明和文件对应 文件上传页面中,如果有多个文件域又有多个相对应的文件说明时, 文件和说明如何对应? 我们在表单中给对应的file变量和text变 ...
- Spring Boot属性文件配置文档(全部)
This sample file is meant as a guide only. Do not copy/paste the entire content into your applicatio ...
- spring 及 spring boot 资源文件配置
Spring配置文件引入xml文件: <import resource=" " />标签使用总结 https://www.cnblogs.com/javahr/p/83 ...
- spring boot实现文件上传下载
spring boot 引入”约定大于配置“的概念,实现自动配置,节约了开发人员的开发成本,并且凭借其微服务架构的方式和较少的配置,一出来就占据大片开发人员的芳心.大部分的配置从开发人员可见变成了相对 ...
- 【Spring Boot】Spring Boot之使用Alibaba Cloud Toolkit(Idea插件)本地一键部署Spring Boot项目到远程服务器
一.Alibaba Cloud Toolkit(Idea插件)的安装 1)Alibaba Cloud Toolkit 介绍 Cloud Toolkit 是本地 IDE 插件,帮助开发者更高效地开发.测 ...
随机推荐
- css3的3D变形
一.坐标系 1.是我们熟悉的右手坐标系:伸出右手,让拇指和食指成L形,大拇指向为右,食指向上,中指指向前方,这样,拇指.食指.中指的指向分别是X.Y.Z轴的正方向. 2.是我们CSS3中的3D坐标:伸 ...
- leyou_06——FastDFS在Nginx下的安装与测试
1.FastDFS FastDFS是由淘宝的余庆先生所开发的一个轻量级.高性能的开源分布式文件系统.用纯C语言开发,功能丰富: 文件存储 文件同步 文件访问(上传.下载) 存取负载均衡 在线扩容 2. ...
- 强制以32位ie运行程序
最近被一个问题给郁闷住了.给电脑重装系统后,发现发布好的程序.或者VS2012总是以64位ie运行程序,这样的话skyline的三维控件无法显示.到现在我是确定ie64无法识别skyline的控件. ...
- python进阶_浅谈面向对象进阶
python进阶_浅谈面向对象进阶 学了面向对象三大特性继承,多态,封装.今天我们看看面向对象的一些进阶内容,反射和一些类的内置函数. 一.isinstance和issubclass class F ...
- [转载] OpenCV2.4.3 CheatSheet学习(三)
四.图像处理(呵呵,重头戏来了) 1. 滤波 filter2D() 用核函数对图像做卷积. sepFilter2D() 用分解的核函数对图像做卷积. 首先,图像的每一行与一维的核kernelX做卷积: ...
- mybatis学习:mybatis的注解开发CRUD操作
Dao层: public interface IUserDao { /** * 查询所有结果 * @return */ @Select("select * from user") ...
- TZOJ 4292 Count the Trees(树hash)
描述 A binary tree is a tree data structure in which each node has at most two child nodes, usually di ...
- [jnhs]教训之jsp页面无法用jstl取值的坑.真他妈的奇葩,实体类的属性名不能用大写
结果页面永远都是空 调试发现,数据正常的塞进去了 问题解决: https://zhidao.baidu.com/question/570584436.html 实体类的属性名,首字母不能大写,改成小写 ...
- spring JdbcTemplate在spring的ioc中使用
package com.com.jdbctemplate; import org.springframework.context.ApplicationContext; import org.spri ...
- Elasticsearch连接类(带密码)
/** * 获取ES连接类 * * @author 陈康 * @description * @create 2019/08/15 **/ @Component("ElasticsearchR ...