Apache camel apache骆驼幂等消费密钥删除

Apache camel apache骆驼幂等消费密钥删除,apache-camel,Apache Camel,我有一个如下设置 我遇到的问题是,在使用OnException中的seda组件时,当抛出异常时(在下面的第行中),不会删除幂等存储库中的密钥。当我在OnException中更改为使用direct时,将从缓存中删除密钥。在这两次试验中,电子邮件也被正确发送 我的问题是: 在OnException中使用seda时,为什么没有从存储库缓存中删除密钥 在OnException中使用seda是否存在问题 以下是路线: MyRouteClass1 onException(Exception.class)

我有一个如下设置

我遇到的问题是,在使用
OnException
中的
seda
组件时,当抛出异常时(在下面的第行中),不会删除幂等存储库中的密钥。当我在
OnException
中更改为使用
direct
时,将从缓存中删除密钥。在这两次试验中,电子邮件也被正确发送

我的问题是:

  • OnException
    中使用
    seda
    时,为什么没有从存储库缓存中删除密钥
  • OnException
    中使用
    seda
    是否存在问题
  • 以下是路线:

    MyRouteClass1

    onException(Exception.class)
      .setHeader("subjectText", simple("failure email!"))
      .to("seda:notifySupportOnFailure")
      .end();
    
    from("direct:findWorkItems")
        .bean(someService, "findWorkItems")
        .split(body())
          .throttle(1).timePeriodMillis(5000L)
          .to("direct:handleWorkItem")
          .choice().when(header("resultId").isGreaterThan(0))
          .bean(someService, "updateWorkItemToHandled")
          .end();
    
    from("direct:handleWorkItem")
        .idempotentConsumer(simple("${body.workItemId}"), duplicatesRepo)
        .bean(someService, "handleWorkItem")  // e.g. exception would be thrown within here
        .setHeader("resultId", body())
        .end();
    
    MyRouteClass2

    from("seda:notifySupportOnFailure")
      .setHeader("from", simple("sender@mail.com"))
      .setHeader("to", simple("recipient@mail.com"))
      .setBody(simple("Failure:\n ${exception.message} \n\ndetail: \n${body}"))
      .to("smtp://localhost")
      .log("Failure email now sent.")
      .end();
    
    我还尝试了另一种解决方法。我已根据以下内容修改了OneException条款。这允许在引发异常时从存储库中删除密钥。我想知道这是不是一个正确的方法

    onException(Exception.class)
      .setHeader("subjectText", simple("failure email!"))
      .multicast().to("seda:notifySupportOnFailure").end()
      .end();
    

    解决方法是将幂等消费调用放在父路由“findWorkItems”中,并将其上的CompletionAnger标志设置为true

    onException(Exception.class)
      .setHeader("subjectText", simple("failure email!"))
      .to("seda:notifySupportOnFailure")
      .end();
    
    from("direct:findWorkItems")
        .idempotentConsumer(simple("${body.workItemId}"), duplicatesRepo).completionEager(true)
        .bean(someService, "findWorkItems")
        .split(body())
          .throttle(1).timePeriodMillis(5000L)
          .to("direct:handleWorkItem")
          .choice().when(header("resultId").isGreaterThan(0))
          .bean(someService, "updateWorkItemToHandled")
          .end();
    
    from("direct:handleWorkItem")
        .bean(someService, "handleWorkItem")  // e.g. exception would be thrown within here
        .setHeader("resultId", body())
        .end();
    

    解决方法是将幂等消费调用放在父路由“findWorkItems”中,并将其上的CompletionAnger标志设置为true

    onException(Exception.class)
      .setHeader("subjectText", simple("failure email!"))
      .to("seda:notifySupportOnFailure")
      .end();
    
    from("direct:findWorkItems")
        .idempotentConsumer(simple("${body.workItemId}"), duplicatesRepo).completionEager(true)
        .bean(someService, "findWorkItems")
        .split(body())
          .throttle(1).timePeriodMillis(5000L)
          .to("direct:handleWorkItem")
          .choice().when(header("resultId").isGreaterThan(0))
          .bean(someService, "updateWorkItemToHandled")
          .end();
    
    from("direct:handleWorkItem")
        .bean(someService, "handleWorkItem")  // e.g. exception would be thrown within here
        .setHeader("resultId", body())
        .end();
    

    添加一些额外的信息。存储库如下所示:IdempotentRepository duplicatesepo=MemoryIdempotentRepository.MemoryIdempotentRepository(100);正在使用的ApacheCamel版本是2.16.2,以添加一些关于此的额外信息。存储库如下所示:IdempotentRepository duplicatesepo=MemoryIdempotentRepository.MemoryIdempotentRepository(100);使用的Apache Camel版本是2.16.2,我已经尝试过这种变通方法。当我将completionEager标志设置为true时,将在OnException子句中从存储库中删除密钥。但这是正确的方法吗?我已经尝试过这种变通方法。当我将completionEager标志设置为true时,将在OnException子句中从存储库中删除密钥。但这是正确的做法吗?