动态如何“从"开始端点和交流在骆驼中工作? [英] How do dynamic "from" endpoints and exchanges work in camel?

查看:90
本文介绍了动态如何“从"开始端点和交流在骆驼中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在动态路由概念和消费者规则方面苦苦挣扎.

I'm sort of struggling with the dynamic routing concept and consumer rules.

因此,假设我有一条包含交换数据的路由,然后我想在"from"端点中的另一条路由中使用交换的标头.

So let's say I have a route with exchange data, and then I want to use a header from the exchange in a different route in the "from" endpoint.

我认为它看起来像这样:

I think it would look something like this:

路线1:

from("file:/dir1")
...
.to ("direct:start");

路线2:

from("direct: start")//get the old exchange data
.from("file:/dir1/?fileName=${header.myHeader}")//start consuming from a different endpoint using old exchange data
...
.to("direct: end);

这些步骤对我来说似乎是正确的,但我感觉我有点像在污染交易.

So those steps seems right to me, but I feel like Im sort of polluting the exchange.

对我来说,我使用动态路由,但同时我还创建了一个新的使用者.那意味着我要创建新的交易权吗?那么,骆驼如何知道在其余路线中选择和使用哪个交易所呢?

To me, Im using dynamic routing but Im also creating a new consumer at the same time. That means Im creating a new exchange right? So, how does camel know which exchange to pick and use in the rest of the route?

起初,我认为它可能将它们组合在一起,但是我做了一些进一步的挖掘,发现您实际上需要使用浓缩"来添加到现有的交易所中.

At first I thought it probably combined them, but I did a bit more digging and found that you actually need to use "enrich" to add to an existing exchange.

有人可以解释骆驼如何处理这种情况吗?如果您有一个例子,那就太好了.我没有在骆驼包中搜索一个.

Can someone explain how camel handles this sort of scenario? If you have an example that would be great too. I searched for one in the camel package with no success.

推荐答案

您可以通过假设您的第一个路线用于将文件名添加到标题中,例如:

Let's say your first route is used to add file name to the header for instance like this:

from("timer:trigger?repeatCount=1")
.routeId("define-file-name")
.setHeader("myHeader", constant("file.txt"))
.to("direct:start");

然后,您的第二条路线可以使用来自交换头的信息来轮询该文件.

Then your second route can poll for that file using the information from the exchange header like this.

from("direct:start")
.routeId("poll-file")
.pollEnrich().simple("file://dir1?fileName=${in.header.myHeader}").timeout(10000)
.log("${body}");

这篇关于动态如何“从"开始端点和交流在骆驼中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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