gpt4 book ai didi

activemq - Camel -内容丰富器: enrich() vs pollEnrich()

转载 作者:行者123 更新时间:2023-12-04 10:07:52 24 4
gpt4 key购买 nike

第一个问题:

我无法真正理解enrich()pollEnrich()之间的区别。也许 Camel 使用的术语不是很好。

我在这里阅读:http://camel.apache.org/content-enricher.html

Content enrichment using the enrich DSL element

Camel comes with two flavors of content enricher in the DSL

  • enrich
  • pollEnrich

enrich uses a Producer to obtain the additional data. It is usually used for Request Reply messaging, for instance to invoke an external web service. pollEnrich on the other hand uses a Polling Consumer to obtain the additional data. It is usually used for Event Message messaging, for instance to read a file or download a FTP file.



我不知道有什么区别。他们俩似乎都通过消费获得了其他数据(Web服务响应,FTP文件)。那么为什么他们说获得Web服务响应是由“生产者”完成的呢?

第二个问题:

在“行动中的 Camel ”一书中。 72他们说:

Enrich and pollEnrich can’t access information in the current exchange

Neither enrich nor pollEnrich can leverage any information from the current exchange. This means, for example, that you can’t store a filename header on the exchange for pollEnrich to use to select a particular file. This may change in the future if the Camel team can find a solution.



但是,它们提供了类似于以下代码示例的用于实现聚合策略的代码:
public class ExampleAggregationStrategy implements AggregationStrategy {

public Exchange aggregate(Exchange original, Exchange resource) {
Object originalBody = original.getIn().getBody();
Object resourceResponse = resource.getIn().getBody();
Object mergeResult = ... // combine original body and resource response
if (original.getPattern().isOutCapable()) {
original.getOut().setBody(mergeResult);
} else {
original.getIn().setBody(mergeResult);
}
return original;
}

}

在此示例中,我看到他们可以访问 Exchange original,这不是“当前交换”吗?如果不是,那么“原始交换”代表什么交换?
所谓“当前交换”是什么意思?

最佳答案

区别在于:

  • enrich假定您要使用传入的Exchange作为另一个服务请求的参数。例如,传入的Exchange可以是一个userID,但是您确实需要整个User对象,因此您可以通过将userID传递到返回返回成为Exchange的User对象的REST服务的enrich,以此类推。
  • pollEnrich假定传入的Exchange是一个简单的触发器,它告诉PollingConsumer查找数据并创建一个Exchange(忽略传入的Exchange的内容)。例如,您可能有一个计时器或其他业务流程事件,需要拾取一个文件进行处理,等等。也就是说,传入的Exchange数据不用于动态配置PollingConsumer ...仅URI用于此目的。

  • 就是说,从 Camel 2.12开始,有一个选项可以指定一种聚合策略,以组合 enrichpollEnrich的传入/返回交换

    有关聚合策略的pollEnrich示例,请参见 this unit test

    关于activemq - Camel -内容丰富器: enrich() vs pollEnrich(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19098466/

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