1 回答
TA贡献1775条经验 获得超11个赞
Camel File2 组件支持可插入表达式。创建实现Expression的bean并将其传递给带有idempotentKey=#myExpressionBean.
我不认为,为每次轮询计算文件内容的 md5 哈希值是个好主意,但这是可能的。
表达
@Component
class FileContentMD5Expression implements Expression {
@Override
public <T> T evaluate(Exchange exchange, Class<T> type) {
if (type != String.class){
throw new IllegalArgumentException("This is String only expression");
}
try (FileInputStream fis = new FileInputStream(((File)exchange.getIn(GenericFileMessage.class).getGenericFile().getFile()))) {
return type.cast(DigestUtils.md5Hex(fis));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
消费者
from("file://somewhere?idempotent=true&idempotentKey=#fileContentMD5Expression")
添加回答
举报
