camel-ftp 使用笔记

解决中文目录乱码问题

1
ftpClient.controlEncoding=gb2312

idempotentConsumer

file

1
2
3
4
5
6
7
8
9
10
11
12
// tmp 是一个路径:./../tmp
// 通过文件名缓存,如果缓存中已经有这个文件名,怎不再处理这个文件
ValueBuilder messageIdExpression = header(Exchange.FILE_PATH)
.append("#").append(header(Exchange.FILE_LAST_MODIFIED))
.append("#").append(header(Exchange.FILE_LENGTH));
FileIdempotentRepository idempotentRepository =
FileIdempotentRepository.fileIdempotentRepository(new File(tmp, this.getClass().getSimpleName() + ".txt"), 100 * 1024, 5 * 1024 * 1024);

from(url.toString())
.idempotentConsumer(messageIdExpression, idempotentRepository)
.process(arrearsProcessor)
.log(LoggingLevel.INFO, log, "finished processor the file ${file:path}.");

jpa

1
2
3
4
5
6
7
8
9
10
11
12
13
@Resource
private EntityManagerFactory entityManagerFactory;

ValueBuilder messageIdExpression = header(Exchange.FILE_PATH)
.append("#").append(header(Exchange.FILE_LAST_MODIFIED))
.append("#").append(header(Exchange.FILE_LENGTH));
JpaMessageIdRepository idempotentRepository =
JpaMessageIdRepository.jpaMessageIdRepository(entityManagerFactory,
this.getClass().getName());
from(url.toString())
.idempotentConsumer(messageIdExpression, idempotentRepository)
.process(arrearsProcessor)
.log(LoggingLevel.INFO, log, "finished processor the file ${file:name}.");

filter

1
2
3
4
5
// 标识文件名是“20180803.txt”时,才执行之后的流程
.filter(header(Exchange.FILE_NAME).isEqualTo("20180803.txt"))

// 标识文件名不是“20180803.txt”时,才执行之后的流程
.filter(header(Exchange.FILE_NAME).isNotEqualTo("20180803.txt"))

filterFile

1
2
// 只读取包含当天日期的文件:文件前缀_20_20180305.txt
ftp://localhost:22/test?username=xxx&password=xx&filterFile=${file:name} contains ${date:now:yyyyMMdd}

readLock

readLock=rename可以阻止camel读取正在被写入的文件

move

移动文件到同级 done 目录下

1
2
# 移动到同级 done 目录下
ftp://localhost:22/test?username=xxx&password=xx&move=done&readLock=rename

移动并重命名文件

1
ftp://localhost:22/test?username=xxx&password=xx&move=done/{file:name.noext}_${file:modified}.${file:ext}&readLock=rename

参考:org.apache.camel.language.simple.SimpleLanguage.java

  • 本文作者: forever杨
  • 本文链接: https://blog.yl-online.top/posts/6ae6b8a1.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。如果文章内容对你有用,请记录到你的笔记中。本博客站点随时会停止服务,请不要收藏、转载!