Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
@ConsumeTo consume a message you use the @Consume annotation to mark a particular method of a bean as being a consumer method. The uri of the annotation defines the Camel Endpoint to consume from. e.g. lets invoke the public class Foo { @Consume(uri="activemq:cheese") public void onCheese(String name) { ... } } The Bean Binding is then used to convert the inbound Message to the parameter list used to invoke the method . What this does is basically create a route that looks kinda like this from(uri).bean(theBean, "methodName"); When using more than one CamelContext When you use more than 1 CamelContext you might end up with each of them creating a POJO Consuming; therefore use the option Using context option to apply only a certain CamelContextSee the warning above. You can use the @Consume(uri="activemq:cheese", context="camel-1") public void onCheese(String name) { The consumer above will only be created for the CamelContext that have the context id = <camelContext id="camel-1" ...> Using an explicit routeIf 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. For example from(uri).beanRef("myBean", "methodName"); 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). Use the Bean endpointYou can always use the bean endpoint from(uri).to("bean:myBean?method=methodName"); Using a property to define the endpointAvailable as of Camel 2.11 The following annotations @Consume, @Produce, @EndpointInject, now offers a This applies for them all The explanation below applies for all the three annotations, eg @Consume, @Produce, and @EndpointInject For example public class MyService { private String serviceEndpoint; public void setServiceEndpoint(String uri) { this.serviceEndpoint = uri; } public String getServiceEndpoint() { return serviceEndpoint } @Consume(property = "serviceEndpoint") public void onService(String input) { ... } } The bean If you define the bean in Spring XML or Blueprint, then you can configure the property as follows: <bean id="myService" class="com.foo.MyService"> <property name="serviceEndpoint" value="activemq:queue:foo"/> </bean> 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 @Consume(property = "service") public void onService(String input) { 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 @Consume public void onService(String input) { 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. Which approach to use?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. |