Java Camel - 将特定参数从路由传递到通用 bean 方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23910858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 08:58:37  来源:igfitidea点击:

Camel - Passing specific parameters from routes to a generic bean method

javaspringparametersapache-camelspring-bean

提问by abbasdgr8

Let's say I have a Camel route that looks like this :

假设我有一条看起来像这样的骆驼路线:

from("direct:myRoute")
        .setHeader("someHeader", simple("some header value"))
        .beanRef("myBean", "beanMethod");

And I have a bean that I cannot changethat looks like this :

我有一个豆子cannot change,看起来像这样:

public class MyBean {
    public void beanMethod(String headerExpected) {
        // do something with the value here.
    }
}

Basically, I want to pass the value of someHeaderfrom myRouteto beanMethodwithin MyBean.

基本上,我想传递的价值someHeadermyRoutebeanMethod为myBean

Knowing that beanMethod can accept a String, how can I pass the value of the header someHeaderfrom the route so that it is accepted as a String within beanMethod?

知道 beanMethod 可以接受 a String,我如何从路由中传递标题someHeader的值,以便它在beanMethod 中被接受为 String ?

采纳答案by Matthew Wilson

You can pass parameters in the way you described like this:

您可以按照您描述的方式传递参数,如下所示:

from("direct:myRoute")
.setHeader("someHeader", simple("some header value"))
.to("bean:myBean?method=beanMethod(${header.someHeader})")

More info, including other methods for bean binding can be found here http://camel.apache.org/bean-binding.html

更多信息,包括其他 bean 绑定方法可以在这里找到http://camel.apache.org/bean-binding.html