问题
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