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

不羁的心 提交于 2019-12-04 10:49:45

问题


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 change that looks like this :

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

Basically, I want to pass the value of someHeader from myRoute to beanMethod within MyBean.

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


回答1:


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



来源:https://stackoverflow.com/questions/23910858/camel-passing-specific-parameters-from-routes-to-a-generic-bean-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!