Versions Compared

Key

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

Bean Component

The bean: component binds beans to Camel message exchanges.

URI format

Code Block
bean:someName[?methodName=someMethod]

Where someName can be any string which is used to lookup the bean in the Registry and someMethod defines the name of the method to invoke.

This will use the Bean Binding to map the message exchange to the bean.

Using

The object instance that is used to consume messages must be explicitly registered with the Registry. For example if you are using Spring you must define the bean in the spring.xml; or if you don't use Spring then put the bean in JNDI.

Wiki Markup
{snippet:id=register|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java}

Once an endpoint has been registered, you can build Camel routes that use it to process exchanges.

Wiki Markup
{snippet:id=route|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java}

A bean: endpoint cannot be defined as the input to the route; i.e. you cannot consume from it, you can only route from some inbound message Endpoint to the bean endpoint as output. So consider using a direct: or queue: endpoint as the input.

You can use the createProxy() methods on ProxyHelper to create a proxy that will generate BeanExchanges and send them to any endpoint:

Wiki Markup
{snippet:id=invoke|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java}
Include Page
CAMEL:Bean Binding
CAMEL:Bean Binding
Include Page
CAMEL:Endpoint See Also
CAMEL:Endpoint See Also