How do dynamic quot;fromquot; endpoints and exchanges work in camel?(动态“从怎么做?端点和交换在骆驼中工作?)
问题描述
我有点纠结于动态路由概念和消费者规则.
I'm sort of struggling with the dynamic routing concept and consumer rules.
假设我有一个包含交换数据的路由,然后我想在来自"端点的不同路由中使用来自交换的标头.
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.
对我来说,我使用的是动态路由,但同时我也创建了一个新的消费者.这意味着我正在创建一个新的交易所,对吧?那么,camel 如何知道在其余路线中选择和使用哪个交易所?
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.
推荐答案
你可以通过 Content Enricher 模式.
假设您的第一个路由用于将文件名添加到标题中,例如:
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}");
这篇关于动态“从"怎么做?端点和交换在骆驼中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:动态“从"怎么做?端点和交换在骆驼中工作?


- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01