e.g. lets invoke the onCheese() method with the String body of the inbound JMS message from ActiveMQ on the cheese queue; this will use the Type Converter to convert the JMS ObjectMessage or BytesMessage to a String - or just use a TextMessage from JMS
What this does is basically create a route that looks kinda like this
See the warning above.
You can use the context option to specify which CamelContext the consumer should only apply for. For example:
The consumer above will only be created for the CamelContext that have the context id = camel-1. You set this id in the XML tag:
If you want to invoke a bean method from many different endpoints or within different complex routes in different circumstances you can just use the normal routing DSL or the Spring XML configuration file.
which will then look up in the Registry and find the bean and invoke the given bean name. (You can omit the method name and have Camel figure out the right method based on the method annotations and body type).
You can always use the bean endpoint
Available as of Camel 2.11
The following annotations @Consume, @Produce, @EndpointInject, now offers a property attribute you can use to define the endpoint as a property on the bean. Then Camel will use the getter method to access the property.
The bean MyService has a property named serviceEndpoint which has getter/setter for the property. Now we want to use the bean for POJO Consuming, and hence why we use @Consume in the onService method. Notice how we use the property = "serviceEndpoint to configure the property that has the endpoint url.
If you define the bean in Spring XML or Blueprint, then you can configure the property as follows:
This allows you to configure the bean using any standard IoC style.
Camel offers a naming convention which allows you to not have to explicit name the property.
1. Use the property name if explicit given
So in the example above, we could have defined the @Consume annotation as
Now the property is named 'service' which then would match step 3 from the algorithm, and have Camel invoke the getServiceEndpoint method.
We could also have omitted the property attribute, to make it implicit
Now Camel matches step 5, and loses the prefix on in the name, and looks for 'service' as the property. And because there is a getServiceEndpoint method, Camel will use that.
Using the @Consume annotations are simpler when you are creating a simple route with a single well defined input URI.
However if you require more complex routes or the same bean method needs to be invoked from many places then please use the routing DSL as shown above.