Repository: camel Updated Branches: refs/heads/master 7e6ebc3cb -> d4951f441
Added bean docs to Gitbook Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b40a5b87 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b40a5b87 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b40a5b87 Branch: refs/heads/master Commit: b40a5b87cd8cb5da1ed79e806e6bf499312c2b1d Parents: 7e6ebc3 Author: Andrea Cosentino <anco...@gmail.com> Authored: Thu Jun 9 16:29:10 2016 +0200 Committer: Andrea Cosentino <anco...@gmail.com> Committed: Thu Jun 9 16:29:10 2016 +0200 ---------------------------------------------------------------------- camel-core/src/main/docs/bean.adoc | 160 ++++++++++++++++++++++++++++++++ docs/user-manual/en/SUMMARY.md | 1 + 2 files changed, 161 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b40a5b87/camel-core/src/main/docs/bean.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/bean.adoc b/camel-core/src/main/docs/bean.adoc new file mode 100644 index 0000000..fc8d348 --- /dev/null +++ b/camel-core/src/main/docs/bean.adoc @@ -0,0 +1,160 @@ +[[Bean-BeanComponent]] +Bean Component +~~~~~~~~~~~~~~ + +The *bean:* component binds beans to Camel message exchanges. + +[[Bean-URIformat]] +URI format +^^^^^^^^^^ + +[source,java] +--------------------- +bean:beanID[?options] +--------------------- + +Where *beanID* can be any string which is used to look up the bean in +the link:registry.html[Registry] + +[[Bean-Options]] +Options +^^^^^^^ + + +// component options: START +The Bean component has no options. +// component options: END + + + +// endpoint options: START +The Bean component supports 7 endpoint options which are listed below: + +{% raw %} +[width="100%",cols="2s,1,1m,1m,5",options="header"] +|======================================================================= +| Name | Group | Default | Java Type | Description +| beanName | producer | | String | *Required* Sets the name of the bean to invoke +| method | producer | | String | Sets the name of the method to invoke on the bean +| cache | advanced | false | boolean | If enabled Camel will cache the result of the first Registry look-up. Cache can be enabled if the bean in the Registry is defined as a singleton scope. +| exchangePattern | advanced | InOnly | ExchangePattern | Sets the default exchange pattern when creating an exchange. +| multiParameterArray | advanced | false | boolean | How to treat the parameters which are passed from the message body; if it is true the message body should be an array of parameters. Note: This option is used internally by Camel and is not intended for end users to use. +| parameters | advanced | | Map | Used for configuring additional properties on the bean +| synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). +|======================================================================= +{% endraw %} +// endpoint options: END + + +You can append query options to the URI in the following format, +`?option=value&option=value&...` + +[[Bean-Using]] +Using +^^^^^ + +The object instance that is used to consume messages must be explicitly +registered with the link:registry.html[Registry]. For example, if you +are using Spring you must define the bean in the Spring configuration, +`spring.xml`; or if you don't use Spring, by registering the bean in +JNDI. + +Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: +Index: 20, Size: 20 + +Once an endpoint has been registered, you can build Camel routes that +use it to process exchanges. + +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 +link:endpoint.html[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 +http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/component/bean/ProxyHelper.html[ProxyHelper] +to create a proxy that will generate BeanExchanges and send them to any +endpoint: + +And the same route using Spring DSL: + +[source,xml] +---------------------------- +<route> + <from uri="direct:hello"> + <to uri="bean:bye"/> +</route> +---------------------------- + +[[Bean-Beanasendpoint]] +Bean as endpoint +^^^^^^^^^^^^^^^^ + +Camel also supports invoking link:bean.html[Bean] as an Endpoint. In the +route below: + +What happens is that when the exchange is routed to the `myBean` Camel +will use the link:bean-binding.html[Bean Binding] to invoke the bean. + + The source for the bean is just a plain POJO: + +Camel will use link:bean-binding.html[Bean Binding] to invoke the +`sayHello` method, by converting the Exchange's In body to the `String` +type and storing the output of the method on the Exchange Out body. + +[[Bean-JavaDSLbeansyntax]] +Java DSL bean syntax +^^^^^^^^^^^^^^^^^^^^ + +Java DSL comes with syntactic sugar for the link:bean.html[Bean] +component. Instead of specifying the bean explicitly as the endpoint +(i.e. `to("bean:beanName")`) you can use the following syntax: + +[source,java] +------------------------------------------------------- +// Send message to the bean endpoint +// and invoke method resolved using Bean Binding. +from("direct:start").beanRef("beanName"); + +// Send message to the bean endpoint +// and invoke given method. +from("direct:start").beanRef("beanName", "methodName"); +------------------------------------------------------- + +Instead of passing name of the reference to the bean (so that Camel will +lookup for it in the registry), you can specify the bean itself: + +[source,java] +--------------------------------------------------------------- +// Send message to the given bean instance. +from("direct:start").bean(new ExampleBean()); + +// Explicit selection of bean method to be invoked. +from("direct:start").bean(new ExampleBean(), "methodName"); + +// Camel will create the instance of bean and cache it for you. +from("direct:start").bean(ExampleBean.class); +--------------------------------------------------------------- + +[[Bean-BeanBinding]] +Bean Binding +^^^^^^^^^^^^ + +How bean methods to be invoked are chosen (if they are not specified +explicitly through the *method* parameter) and how parameter values are +constructed from the link:message.html[Message] are all defined by the +link:bean-binding.html[Bean Binding] mechanism which is used throughout +all of the various link:bean-integration.html[Bean Integration] +mechanisms in Camel. + +[[Bean-SeeAlso]] +See Also +^^^^^^^^ + +* link:configuring-camel.html[Configuring Camel] +* link:component.html[Component] +* link:endpoint.html[Endpoint] +* link:getting-started.html[Getting Started] + +* link:class.html[Class] component +* link:bean-binding.html[Bean Binding] +* link:bean-integration.html[Bean Integration] + http://git-wip-us.apache.org/repos/asf/camel/blob/b40a5b87/docs/user-manual/en/SUMMARY.md ---------------------------------------------------------------------- diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md index 7e0f244..e4430fc 100644 --- a/docs/user-manual/en/SUMMARY.md +++ b/docs/user-manual/en/SUMMARY.md @@ -96,6 +96,7 @@ * [Bam](bam.adoc) * [Barcode](barcode-data-format.adoc) * [Base64](base64.adoc) + * [Bean](bean.adoc) * [Beanstalk](beanstalk.adoc) * [Bean-validator](bean-validator.adoc) * [Bindy](bindy.adoc)