Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

@MessageDriven or @Consume

...

title@MessageDriven is @deprecated

...

@Consume

...

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.

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

...

Warning
titleWhen using more than one CamelContext

When you use more than 1 CamelContext you might end up with each of them creating a POJO Consuming.
In Camel 2.0 there is a new option ; therefore use the option context on @Consume that allows you to specify which CamelContext id/name you want it to apply for.

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:

...

Which approach to use?

Using the @MessageDriven/ @Consume annotations are simpler when you are creating a simple route with a single well defined input URI.

...