gpt4 book ai didi

java - MD5 作为 Apache Camel 中的幂等 key

转载 作者:行者123 更新时间:2023-11-30 01:55:32 28 4
gpt4 key购买 nike

默认行为是使用绝对文件路径来唯一标识文件 - 我想自定义它以使用文件的 md5 校验和。

是否可以简单地实现自定义幂等 key (不使用“文件语言”)?

最佳答案

Camel File2 组件支持可插入表达式。创建执行 Expression 的 bean并将其传递给使用 idempotKey=#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")

关于java - MD5 作为 Apache Camel 中的幂等 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54657032/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com