首页 文章

Camel多次使用来自同一URI的pollEnrich返回null body

提问于
浏览
2

我有2条路线 . 第一个路由使用poll enrich来检查文件是否存在 . 第二条路线使用同一uri上的民意调查来读取和处理文件 . 第一个路由通过SEDA队列调用第二个路由,如下所示:

public void configure() throws Exception {
    String myFile = "file://myDir?fileName=MyFile.zip&delete=false&readLock=none";

    from("direct:test")
       .pollEnrich(myFile, 10000)
    .to("seda:myQueue")
    ;

    from("seda:myQueue")
        .pollEnrich(myFile, 10000)
        .log("Do something with the body")
    ;
}

就目前而言,如果我执行第一条路线,民意调查就会找到一个文件,但是当第二条路线中的民意调查丰富时,它会返回一个空体 . 如果我只是自己执行第二个路由,它会正确检索文件 .

Why does the second poll enrich return null, is the file locked? (I was hoping using a combination of noop,readLock, and delete=false would prevent any locking)

Does camel consider the second poll enrich as a duplicate, therefore filtering it out? (I have tried implementing my own IdempotentRepository to return false on contains(), but the second pollEnrich still returns null)

您可能想知道为什么我'm trying to enrich from 2 routes, the first route has to check if a number of files exist, only when all files are present (i.e., pollEnrich doesn' t返回null)第二条路线可以开始处理它们 .

我可以使用pollEnrich的替代品吗?我想也许我需要创建一个通过URI检索文件并将其作为正文返回的bean .

我正在使用骆驼2.11.0

5 回答

  • 0

    我意识到这是一个古老的话题,但我遇到了类似的问题 .
    我建议你试试选择:

    noop=true
    

    你已经拥有的,和

    idempotent=false
    

    告诉 Camel 它是 OK 两次处理同一个文件 .

    Update after testing:

    我实际上用上面提到的两种设置对它进行了测试,它工作了一些时间,但是在中等负载下,它失败了,即为某些交换返回null body,尽管不是全部 .

    文档表明设置 noop=true 会自动设置 idempotent=true ,因此我不确定在这种情况下是否遵循幂等设置 .

  • 0

    你有没有使用一条路线的具体原因是什么?

    我不明白你为什么要使用两条路线 . 文件组件可以检查文件是否存在,如果是,请将其拉出 . 如果您担心要记住这些文件而不能获得重复项,则可以使用幂等存储库 . 至少,基于你的问题,我认为你不需要使用两条路线和内容丰富的EIP来复杂化逻辑 .

  • 0

    第二个路由返回NULL,因为该文件已在第一个路由中消耗...如果您只是在所有文件都存在时查找信号消息,那么请使用文件消费者以及aggregator和可能的claim check以避免随身携带内存中的大型有效载荷等......

  • -1

    正如您可能已经了解到的那样,这并不像人们预期的那样有效

    noop=true&idempotent=false
    

    我的猜测是Camel忽略了 idempotent=false ,并且据记载使用了MemoryMessageIdRepository的实例 . 要解决此问题,可以将文件 endpoints 配置为使用自定义幂等仓库:

    noop=true&idempotentRepository=#myRepo
    

    并在注册表或spring上下文中注册自定义存储库:

    @Component("myRepo")
    public class MyRepo implements IdempotentRepository {
        @Override
        public boolean contains(Object o) {
            return false;
        }
        ...
    }
    
  • 1

    使用strategyMethodAllowNull =“true”尝试pollEnrich . 默认情况下,此值为false . 如果为false,则聚合策略将查找现有的Exchange正文,以聚合从文件返回的内容 . 当我们使strategyMethodAllowNull =“true”时,现有的主体被视为null . 所以每次,文件的内容都被设置到当前的交换体中

相关问题