如何在Apache Camel YAML DSL中使用标头组合来定义幂等消费者?

huangapple go评论70阅读模式
英文:

How to define an idempotent consumer in Apache Camel YAML DSL using a combination of headers?

问题

抱歉,您的请求有点复杂,不容易直接提取出代码部分。以下是您要翻译的内容:

"CamelAwsS3Key" 头部之外,我还想在 YAML DSL 路由中的 "idempotent-consumer" 规范中包括 "CamelAwsS3LastModified" 头部,以确保在此路由运行时更新了 S3 上的文件不会被跳过。 与 Java DSL 中的等效路由并附加如下所示的 "CamelAwsS3LastModified" 键可以正常工作:

route = from(fromEndpoint).
             idempotentConsumer(header("CamelAwsS3Key").
                  append(header("CamelAwsS3LastModified")), idempotentRepository);

我该如何在 YAML DSL 路由中的 "idempotent-consumer" 规范中以与上述相同的方式定义组合的 "header"?

英文:

I am using the Camel Main component version 3.19 with the following YAML DSL route to successfully load files from an AWS/S3 bucket to the local file system:

- beans:
    - name: IdempotentRepositoryBean
      type: org.apache.camel.support.processor.idempotent.MemoryIdempotentRepository

- route:
    from:
      uri: "aws2-s3:arn:aws:s3:someBucket"
      parameters:
        # The AWS region hosting the bucket and the access credentials
        # are obtained from Properties file.
        amazonS3Client: "#awss3SourceClient"
        deleteAfterRead: "false"
      steps:
        - idempotent-consumer:
            idempotent-repository: "IdempotentRepositoryBean"
            header: "CamelAwsS3Key"
            skip-duplicate: true
        - set-header:
            name: "CamelFileName"
            simple: "${header.CamelAwsS3Key}"
        - to:
            uri: "file:C:/..."

However, in addition to the header CamelAwsS3Key I also want to include the header CamelAwsS3LastModified in order to enforce that files renewed on S3 while this route is running are not skipped.
Using an equivalent route in Java DSL and appending the key CamelAwsS3LastModified as shown below works fine:

   route = from(fromEndpoint).
             idempotentConsumer(header("CamelAwsS3Key").
                  append(header("CamelAwsS3LastModified")), idempotentRepository);

How can I define the combined header as part of the idempotent-consumer spec in the same way in the YAML DSL route above?

答案1

得分: 0

I'm afraid that what you are trying to do is not possible with the YAML DSL. As a workaround, you can replace your expression with the corresponding simple expression, something like:

...
- idempotent-consumer:
    idempotent-repository: "IdempotentRepositoryBean"
    simple: "${header.CamelAwsS3Key}${header.CamelAwsS3LastModified}"
    skip-duplicate: true
...
英文:

I'm afraid that what you are trying to do is not possible with the YAML DSL, as workaround, you can replace your expression with the corresponding simple expression, something like:

...
    - idempotent-consumer:
        idempotent-repository: "IdempotentRepositoryBean"
        simple: "${header.CamelAwsS3Key}${header.CamelAwsS3LastModified}"
        skip-duplicate: true
...

huangapple
  • 本文由 发表于 2023年3月3日 18:33:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75625954.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定