我的问题非常接近这个讨论:https://issues.apache.org/jira/browse/CAMEL-4863。我也被直接的同步行为所困。
我设计了一个这样的应用程序:
ROUTE1: 从(直接:步骤1-IN)。.process(...)到(直接:步骤1出)
Route2到: 从(直接:步骤2-IN)。.process(...)到(直接:步骤2出)
CoreRoute(连接所有步骤): 从(直接:步骤1出)。为了(直接:步骤2英寸)
一年后,我仍然喜欢这种方法。我可以单独实现和测试这些步骤,例如切换到seda:step1-out如果我需要解耦它们。
但seda相当重要的解耦方法:创建一个队列和一个具有固定线程数的线程池。因此,即使您大多数时间需要1个线程,有时需要100个线程,您仍然可以使用100个线程。
有时你只想释放当前的线程,因为它应该让我们说已经解压缩了下一个文件,而不是处理当前的线程。
从我理解的文档中你将使用线程(1,100):
这。(直接:输入一览处理器).split(主体())的螺纹(1100).delay(1000).process(...)到(步过程解压出)
但是将阻止将交换路由到direct-input-list-processor的线程,直到所有线程完成处理。
相反,我希望将交换复制到后续线程并完成当前交换。
答案 0 :(得分:0)
感谢Claus的评论,我想出了以下内容,似乎可以使用 wireTap 执行我想要的操作:
from("direct:step1-in").to("direct:step1-out");
from("direct:step2-in")
.log("receive async")
.delay(1000).to("log:output");
// core route connecting processing step1 and processing step2
from("direct:step1-out").log("send async").wireTap("direct:step2-in")
.executorService(getContext().getExecutorServiceManager().newThreadPool(this,
"step2-worker", 1, 100));
我认为这是要走的路。虽然我很困惑,因为 Camel in Action书中建议: 10.4.3异步调用者使用多个 线程
from("seda:start")
.to("log:A")
.threads(5, 10)
.to("log:B");
这是最明显的方法,但正如此处所述:http://camel.apache.org/seda.html它不是可行的方式,因为它可以结束,建议使用direct而不是seda的替代方案对我不起作用,因此题。此外,seda方式具有无限队列,这是一个潜在的“内存泄漏”,因此每次要使用此模式时都需要决定并设置合适的大小。
@Claus非常感谢你的出色工作!你的答案在整个项目中引导了我很多。如果您认为这是一个很好的解决方案,或者我仍然遗漏了某些东西,您可以澄清一下。我看到的唯一“缺点”是创建一个新的交易所,交易也不会跨越多个处理步骤。
此日志显示了wireTap异步工作的解决方案,并以灵活的方式进行扩展
2017-07-30T16:36:15.607 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.609 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.610 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.614 | -1 | Camel Thread #2 - step2-worker | INFO | --- --- --- route2 | route2 | - receive async
2017-07-30T16:36:15.614 | -1 | Camel Thread #1 - step2-worker | INFO | --- --- --- route2 | route2 | - receive async
2017-07-30T16:36:15.614 | -1 | Camel Thread #3 - step2-worker | INFO | --- --- --- route2 | route2 | - receive async
2017-07-30T16:36:15.614 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.615 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.616 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.616 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.617 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.618 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.618 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.619 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.620 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.620 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.621 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.622 | -1 | Camel Thread #4 - step2-worker | INFO | --- --- --- route2 | route2 | - receive async
2017-07-30T16:36:15.622 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.623 | -1 | Camel Thread #5 - step2-worker | INFO | --- --- --- route2 | route2 | - receive async
2017-07-30T16:36:15.623 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.624 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.624 | -1 | Camel Thread #6 - step2-worker | INFO | --- --- --- route2 | route2 | - receive async
2017-07-30T16:36:15.625 | -1 | Camel Thread #7 - step2-worker | INFO | --- --- --- route2 | route2 | - receive async
2017-07-30T16:36:15.625 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.626 | -1 | Camel Thread #8 - step2-worker | INFO | --- --- --- route2 | route2 | - receive async
2017-07-30T16:36:15.626 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.627 | -1 | Camel Thread #9 - step2-worker | INFO | --- --- --- route2 | route2 | - receive async
2017-07-30T16:36:15.627 | -1 | main | INFO | --- --- --- route3 | route3 | - send async
2017-07-30T16:36:15.628 | -1 | Camel Thread #10 - step2-worker | INFO | --- --- --- route2 | route2 | - receive async
2017-07-30T16:36:15.629 | -1 | main | INFO | --- --- --- route3 | route3 | - send async