How do I set a component parameter of type object to a route using Java DSL?

夙愿已清 提交于 2020-01-06 07:07:22

问题


My objective is to use Camel along with its JMS component.

The route config looks like below-

from("jms:queue:test").to(mybean) 

I would like to add the option of kind 'parameter' and type 'object' to this route -for example the option 'jmsMessageType'.

I saw some other posts that talks about using setProperty() on route definition but I could not find a definite answer. Options of type 'string' and numbers can be appended to the URI but not objects.

JMS has an option of taskExecutor but how can i add an instance of this to URI for routing.


回答1:


I think you confuse parameter with option.

jmsMessageType you are referring is an option of Camel's jms component. Each component can have many options and you can use them by appending with "?" character. For example

from("jms:queue:test?jmsMessageType=text").to(mybean) 

More particular, for the jms component avalable options can be found in http://camel.apache.org/jms.html (see Common and Advanced Options sections)

Property is something different, it has nothing to do with the component, but with the Exchange message that is passed through the endpoints. More details are in Passing values between processors in apache camel




回答2:


I had to resolve this by adding the instances to a custom registry and using them from the endpoint URI

From official Apache Camel page

From Camel 2.0:

When configuring endpoints using URI syntax you can now refer to beans in the Registry using the # notation. If the parameter value starts with a # sign then Camel will lookup in the Registry for a bean of the given type. For instance:

file://inbox?sorter=#mySpecialFileSorter



来源:https://stackoverflow.com/questions/48536444/how-do-i-set-a-component-parameter-of-type-object-to-a-route-using-java-dsl

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