骆驼 - 内容富集器:充实()VS pollEnrich() [英] Camel - content enricher: enrich() vs pollEnrich()

查看:316
本文介绍了骆驼 - 内容富集器:充实()VS pollEnrich()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1ST问题:

我不能够真正理解之间的差异充实() pollEnrich()。也许条款骆驼的用途是没有那么大。

I'm not able to really understand the difference between enrich() and pollEnrich(). Maybe the terms Camel uses are not so great.

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

使用DSL富集元素含量富集

骆驼自带的DSL内容富集器的两种口味

Camel comes with two flavors of content enricher in the DSL


      
  • 充实

  •   
  • pollEnrich

  •   

富集使用制片以获得附加数据。它通常是
  用于请求回复消息,例如调用一个外部
  网络服务。另一方面pollEnrich使用轮询消费者向
  获得的附加数据。它通常被用于事件消息
  消息,例如读取文件或下载FTP文件。

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服务响应由一个生产者做什么?

I don't understand what the difference is. They both seem to get the additional data (Web service response, FTP file) by consuming it. So why do they say getting the Web service response is done by a "producer"?

第二个问题:

在骆驼在行动的书页。 72他们说:

In the "Camel in action" book p. 72 they say:

丰富和pollEnrich不能在目前的汇率获取信息

既不丰富也不pollEnrich可以利用任何信息
  从目前的交流。这意味着,例如,你不能
  文件名头存放在交换pollEnrich用来
  选择一个特定的文件。这可能会在将来如果骆驼改变
  球队能够找到一个解决方案。

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.

不过,他们给出类似以下内容的code例如,对于实现聚合策略:

However they give a code example similar to the following, for implementing an aggregation strategy:

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;
    }

}

在这个例子中我看到,他们有机会获得交易所原,这不正是当前交流?如果不是,那么是什么呢交换原始交换重present?
而且它们意味着什么的当前的汇率?

In this example I see that they have access to the Exchange original, is it not the "current exchange"? If not, then what exchange does the "original exchange" represent? And what do they mean by the "current exchange"?

推荐答案

下面的区别是:


  • 充实假设你想要使用来电交易所作为参数传递给另外一个服务请求。例如,您输入的交易可能是一个用户ID,但你真的需要整个用户对象,所以你可以充实通过将用户ID,以使用户返回REST服务它对象,成为交易所等。

  • enrich assumes you want to use an incoming Exchange as a parameter to an another service request. for example, your incoming Exchange could be a userID, but you really need the entire User object, so you could enrich it by passing the userID to a REST service that returns the User object which becomes the Exchange, etc.

pollEnrich 假定传入Exchange是一个简单的触发器,告诉PollingConsumer查找数据,并创建Exchange(忽略传入交流的内容)。例如,你可以有一个计时器或其他商业活动的过程,需要拿起处理文件等所述,传入的Exchange数据不用于动态配置PollingConsumer ......只有URI被用于此目的。

pollEnrich assumes the incoming Exchange is a simple trigger that tell a PollingConsumer to look for data and create an Exchange (ignoring the contents of the incoming Exchange). For example, you could have a timer or other business process event that requires picking up a file for processing, etc. that said, the incoming Exchange data is NOT used to dynamically configure the PollingConsumer...only the URI is used for this.

这是说,骆驼2.12,有指定聚合战略,以输入/返回交流结合起来,一个选项都充实 pollEnrich

That said, as of Camel 2.12, there is an option to specify an aggregation strategy to combine the incoming/returned Exchanges for both enrich and pollEnrich

请参阅这个单元测试获取pollEnrich的例子与聚合策略

See this unit test for an example of pollEnrich with an aggregation strategy

这篇关于骆驼 - 内容富集器:充实()VS pollEnrich()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆