|
Page Edited :
CAMEL :
Bean Binding
Bean Binding has been edited by Claus Ibsen (Jul 11, 2008). Change summary: Added some more bean binding samples Bean bindingThe binding of a Camel Message to a bean method call can occur in different ways
By default the return value is set on the outbound message body. For example a POJO such as: public class Bar { public String doSomething(String body) { // process the in body and return whatever you want return "Bye World"; }
For example public class Foo { @MessageDriven(uri = "activemq:my.queue") public void doSomething(@Header('JMSCorrelationID') String correlationID, @Body String body) { // process the inbound message here } } In the above you can now pass the Message.getJMSCorrelationID() as a parameter to the method (using the Type Converter to adapt the value to the type of the parameter). Finally you don't need the @MessageDriven annotation; as the Camel route could describe which method to invoke. e.g. a route could look like from("activemq:someQueue"). to("bean:myBean"); Here myBean would be looked up in the Registry (such as JNDI or the Spring ApplicationContext), then the body of the message would be used to try figure out what method to call. If you want to be explicit you can use from("activemq:someQueue"). to("bean:myBean?methodName=doSomething"); And here we have a nifty example for you to show some great power in Camel. You can mix and match the annotations with the normal parameters, so we can have this example with annotations and the Exchange also: public void doSomething(@Header(name = "user") String user, @Body String body, Exchange exchange) { exchange.getIn().setBody(body + "MyBean"); } Using _expression_ LanguagesYou can also use any of the Languages supported in Camel to bind expressions to method parameters when using bean integration. For example you can use any of these annotations...
For example public class Foo { @MessageDriven(uri = "activemq:my.queue") public void doSomething(@Path("/foo/bar/text()") String correlationID, @Body String body) { // process the inbound message here } } |
Unsubscribe or edit your notifications preferences
