@MessageDriven or @Consume
Info | ||
---|---|---|
| ||
@MessageDriven is deprecated in Camel 1.x. You should use @Consume instead. Its removed in Camel 2.0. |
To consume a message you use either the @MessageDriven annotation or from 1.5.0 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.
...
Code Block |
---|
public class Foo { @MessageDriven@Consume(uri="activemq:cheese") public void onCheese(String name) { ... } } |
...
Code Block |
---|
from(uri).bean(theBean, "methodName");
|
Warning | ||
---|---|---|
| ||
When you use more than 1 CamelContext you might end up with each of them creating a POJO Consuming. |
Using context option to apply only a certain CamelContext
Available as of Camel 2.0
See the warning above.
You can use the context
option to specify which CamelContext the consumer should only apply for. For example:
Code Block |
---|
@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 = camel-1
. You set this id in the XML tag:
Code Block | ||||
---|---|---|---|---|
| ||||
<camelContext id="camel-1" ...>
|
Using an explicit route
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.
...