【问题标题】:Apache Camel - moving file with uri from yaml propertiesApache Camel - 使用来自 yaml 属性的 uri 移动文件
【发布时间】:2020-04-30 20:12:24
【问题描述】:

我正在尝试使用 Apache Camel 处理文件,处理后将其移动到特定文件夹,同时保留文件名和目录结构。

我在 application.yml 文件中的内容:

camel-from: "file:/C:/in/received?move=../in/processed/${file:name}&recursive=true&readLock=changed&readLockMarkerFile=false&delay=1000&maxDepth=2&minDepth=2"

使用Java的Route如下:

@Component
@RequiredArgsConstructor
public class TestRoute extends RouteBuilder {

    @Value("${camel-from}")
    private String fromUri;

    @Override
    public final void configure() {
        from(fromUri)
        // rest of code
    }
}

如果我直接在路由中使用字符串,它工作得很好。但是,从 application.yml 文件中读取它,无论我尝试转义哪些字符,我都无法正确读取 uri。 (我总是以错误告终,或者创建诸如处理/名称之类的文件夹,而不是解释 ${file:name})。

有什么想法吗?

谢谢

【问题讨论】:

  • 这看起来像spring-framework#9628。您可以尝试使用move=../in/processed/#{'$'}{file:name} 或该问题中的其他建议吗?
  • 谢谢,成功了!

标签: apache-camel yaml dsl spring-camel


【解决方案1】:

属性替换需要在SPEL 语言中进行转义,因此 Apache Camel 以原始形式获取值。您可以使用#{'$'} 转义它。有一个未解决的问题 spring-framework#9628 关于使这个转义序列更短/更直观。

camel-from: "file:/C:/in/received?move=../in/processed/#{'$'}{file:name}"

【讨论】:

    猜你喜欢
    • 2017-09-17
    • 2015-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多