Apache Camel - <camel:bean 和 <camel:to 之间有什么区别

Apache Camel - What is the difference between <camel:bean and <camel:to

我有一个从 MQ 获取数据的路由,然后我有一个如下所示的序列 XML:

<camel:bean ref="instruction_handler" method="save"/>
<camel:to ref="instruction_handler" />

两者都会按顺序执行,我能注意到的唯一区别是第一行调用方法"save",第二行调用用“@Handler”注释的方法,看起来没有其他行为差异。

您可以像路由一样使用 bean 组件,您可以将它与 beanRef 一起使用。 bean 组件的文档:http://camel.apache.org/bean.html

所以camel:beancamel:to都是为了调用一个bean。在这种情况下,您在第一次调用中指定了要调用的方法,但在第二次调用中您没有指定要调用的方法的名称,因此 Camel 将使用以下规则选择方法(在您的例子中是方法用 @Handler 装饰):http://camel.apache.org/bean-binding.html#BeanBinding-Choosingthemethodtoinvoke