Repository: camel
Updated Branches:
  refs/heads/master 9f618a28a -> 2c153ed4b


Added camel-guava-eventbus 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/2c07a23f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2c07a23f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2c07a23f

Branch: refs/heads/master
Commit: 2c07a23ffa99a136a50a31286ea3c3cbd1ec2c7c
Parents: 9f618a2
Author: Andrea Cosentino <anco...@gmail.com>
Authored: Sat Apr 2 15:02:25 2016 +0200
Committer: Andrea Cosentino <anco...@gmail.com>
Committed: Sat Apr 2 15:02:25 2016 +0200

----------------------------------------------------------------------
 .../src/main/docs/guava-eventbus.adoc           | 203 +++++++++++++++++++
 docs/user-manual/en/SUMMARY.md                  |   1 +
 2 files changed, 204 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2c07a23f/components/camel-guava-eventbus/src/main/docs/guava-eventbus.adoc
----------------------------------------------------------------------
diff --git a/components/camel-guava-eventbus/src/main/docs/guava-eventbus.adoc 
b/components/camel-guava-eventbus/src/main/docs/guava-eventbus.adoc
new file mode 100644
index 0000000..11cc8ea
--- /dev/null
+++ b/components/camel-guava-eventbus/src/main/docs/guava-eventbus.adoc
@@ -0,0 +1,203 @@
+[[GuavaEventBus-GuavaEventBusComponent]]
+Guava EventBus Component
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+*Available since Camel 2.10.0*
+
+The
+http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/eventbus/package-summary.html[Google
+Guava EventBus] allows publish-subscribe-style communication between
+components without requiring the components to explicitly register with
+one another (and thus be aware of each other). The *guava-eventbus:*
+component provides integration bridge between Camel and
+http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/eventbus/package-summary.html[Google
+Guava EventBus] infrastructure. With the latter component, messages
+exchanged with the Guava `EventBus` can be transparently forwarded to
+the Camel routes. EventBus component allows also to route body of Camel
+exchanges to the Guava `EventBus`.
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+------------------------------------------------------------
+<dependency>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-guava-eventbus</artifactId>
+    <version>x.x.x</version>
+    <!-- use the same version as your Camel core version -->
+</dependency>
+------------------------------------------------------------
+
+[[GuavaEventBus-URIformat]]
+URI format
+^^^^^^^^^^
+
+[source,java]
+--------------------------------
+guava-eventbus:busName[?options]
+--------------------------------
+
+Where *busName* represents the name of the
+`com.google.common.eventbus.EventBus` instance located in the Camel
+registry.
+
+[[GuavaEventBus-Options]]
+Options
+^^^^^^^
+
+
+// component options: START
+The Guava EventBus component supports 2 options which are listed below.
+
+[width="100%",cols="2s,1m,8",options="header"]
+|=======================================================================
+| Name | Java Type | Description
+| eventBus | EventBus | To use the given Guava EventBus instance
+| listenerInterface | Class<?> | The interface with method(s) marked with the 
Subscribe annotation. Dynamic proxy will be created over the interface so it 
could be registered as the EventBus listener. Particularly useful when creating 
multi-event listeners and for handling DeadEvent properly. This option cannot 
be used together with eventClass option.
+|=======================================================================
+// component options: END
+
+// endpoint options: START
+The Guava EventBus component supports 7 endpoint options which are listed 
below:
+
+[width="100%",cols="2s,1,1m,1m,5",options="header"]
+|=======================================================================
+| Name | Group | Default | Java Type | Description
+| eventBusRef | common |  | String | To lookup the Guava EventBus from the 
registry with the given name
+| eventClass | common |  | Class<?> | If used on the consumer side of the 
route will filter events received from the EventBus to the instances of the 
class and superclasses of eventClass. Null value of this option is equal to 
setting it to the java.lang.Object i.e. the consumer will capture all messages 
incoming to the event bus. This option cannot be used together with 
listenerInterface option.
+| listenerInterface | common |  | Class<?> | The interface with method(s) 
marked with the Subscribe annotation. Dynamic proxy will be created over the 
interface so it could be registered as the EventBus listener. Particularly 
useful when creating multi-event listeners and for handling DeadEvent properly. 
This option cannot be used together with eventClass option.
+| bridgeErrorHandler | consumer | false | boolean | Allows for bridging the 
consumer to the Camel routing Error Handler which mean any exceptions occurred 
while the consumer is trying to pickup incoming messages or the likes will now 
be processed as a message and handled by the routing Error Handler. By default 
the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with 
exceptions that will be logged at WARN/ERROR level and ignored.
+| exceptionHandler | consumer (advanced) |  | ExceptionHandler | To let the 
consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler 
is enabled then this options is not in use. By default the consumer will deal 
with exceptions that will be logged at WARN/ERROR level and ignored.
+| exchangePattern | advanced | InOnly | ExchangePattern | Sets the default 
exchange pattern when creating an exchange
+| synchronous | advanced | false | boolean | Sets whether synchronous 
processing should be strictly used or Camel is allowed to use asynchronous 
processing (if supported).
+|=======================================================================
+// endpoint options: END
+
+
+[[GuavaEventBus-Usage]]
+Usage
+^^^^^
+
+Using `guava-eventbus` component on the consumer side of the route will
+capture messages sent to the Guava `EventBus` and forward them to the
+Camel route. Guava EventBus consumer processes incoming messages
+http://camel.apache.org/asynchronous-routing-engine.html[asynchronously].
+
+[source,java]
+-------------------------------------------------------
+SimpleRegistry registry = new SimpleRegistry();
+EventBus eventBus = new EventBus();
+registry.put("busName", eventBus);
+CamelContext camel = new DefaultCamelContext(registry);
+
+from("guava-eventbus:busName").to("seda:queue");
+
+eventBus.post("Send me to the SEDA queue.");
+-------------------------------------------------------
+
+Using `guava-eventbus` component on the producer side of the route will
+forward body of the Camel exchanges to the Guava `EventBus` instance.
+
+[source,java]
+----------------------------------------------------------------------
+SimpleRegistry registry = new SimpleRegistry();
+EventBus eventBus = new EventBus();
+registry.put("busName", eventBus);
+CamelContext camel = new DefaultCamelContext(registry);
+
+from("direct:start").to("guava-eventbus:busName");
+
+ProducerTemplate producerTemplate = camel.createProducerTemplate();
+producer.sendBody("direct:start", "Send me to the Guava EventBus.");
+
+eventBus.register(new Object(){
+  @Subscribe
+  public void messageHander(String message) {
+    System.out.println("Message received from the Camel: " + message);
+  }
+});
+----------------------------------------------------------------------
+
+[[GuavaEventBus-DeadEventconsiderations]]
+DeadEvent considerations
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+Keep in mind that due to the limitations caused by the design of the
+Guava EventBus, you cannot specify event class to be received by the
+listener without creating class annotated with `@Subscribe` method. This
+limitation implies that endpoint with `eventClass` option specified
+actually listens to all possible events (`java.lang.Object`) and filter
+appropriate messages programmatically at runtime. The snipped below
+demonstrates an appropriate excerpt from the Camel code base.
+
+[source,java]
+----------------------------------------------------------------------------
+@Subscribe
+public void eventReceived(Object event) {
+  if (eventClass == null || eventClass.isAssignableFrom(event.getClass())) {
+    doEventReceived(event);
+...
+----------------------------------------------------------------------------
+
+This drawback of this approach is that `EventBus` instance used by Camel
+will never generate `com.google.common.eventbus.DeadEvent`
+notifications. If you want Camel to listen only to the precisely
+specified event (and therefore enable `DeadEvent` support), use
+`listenerInterface` endpoint option. Camel will create dynamic proxy
+over the interface you specify with the latter option and listen only to
+messages specified by the interface handler methods. The example of the
+listener interface with single method handling only `SpecificEvent`
+instances is demonstrated below.
+
+[source,java]
+------------------------------------------
+package com.example;
+
+public interface CustomListener {
+
+  @Subscribe
+  void eventReceived(SpecificEvent event);
+
+}
+------------------------------------------
+
+The listener presented above could be used in the endpoint definition as
+follows.
+
+[source,java]
+---------------------------------------------------------------------------------------------
+from("guava-eventbus:busName?listenerInterface=com.example.CustomListener").to("seda:queue");
+---------------------------------------------------------------------------------------------
+
+[[GuavaEventBus-Consumingmultipletypeofevents]]
+Consuming multiple type of events
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+In order to define multiple type of events to be consumed by Guava
+EventBus consumer use `listenerInterface` endpoint option, as listener
+interface could provide multiple methods marked with the `@Subscribe`
+annotation.
+
+[source,java]
+------------------------------------------------
+package com.example;
+
+public interface MultipleEventsListener {
+
+  @Subscribe
+  void someEventReceived(SomeEvent event);
+
+  @Subscribe
+  void anotherEventReceived(AnotherEvent event);
+
+}
+------------------------------------------------
+
+The listener presented above could be used in the endpoint definition as
+follows.
+
+[source,java]
+-----------------------------------------------------------------------------------------------------
+from("guava-eventbus:busName?listenerInterface=com.example.MultipleEventsListener").to("seda:queue");
+-----------------------------------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/camel/blob/2c07a23f/docs/user-manual/en/SUMMARY.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md
index cfd9568..14b03be 100644
--- a/docs/user-manual/en/SUMMARY.md
+++ b/docs/user-manual/en/SUMMARY.md
@@ -143,6 +143,7 @@
     * [Grape](grape.adoc)
     * [Groovy](groovy.adoc)
         * [Groovy DSL](groovy-dsl.adoc)
+    * [Guava Eventbus](guava-eventbus.adoc)
     * [Ironmq](ironmq.adoc)
     * [JMS](jms.adoc)
     * [JMX](jmx.adoc)

Reply via email to