camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Guava EventBus
Date Mon, 25 Mar 2013 20:28:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Guava+EventBus">Guava
EventBus</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~hekonsek">Henryk
Konsek</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        Added info about Guava EventBus listenerInterface option.<br />
    </div>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>|| Name || Default Value
|| Description || <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{eventClass}} | {{null}} |
*Camel 2.10:* 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. <span class="diff-added-words"style="background-color:
#dfd;">This option cannot be used together with {{listenerInterface}} option.</span>
| <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|{{listenerInterface}}|{{null}}|
*Camel 2.11:* 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.| <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h3. Usage <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="GuavaEventBus-GuavaEventBusComponent"></a>Guava EventBus
Component</h2>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>Available since Camel
2.10.0</b><br /></td></tr></table></div>

<p>The <a href="http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/eventbus/package-summary.html"
class="external-link" rel="nofollow">Google Guava EventBus</a> 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 <b>guava-eventbus:</b> component
provides integration bridge between Camel and <a href="http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/eventbus/package-summary.html"
class="external-link" rel="nofollow">Google Guava EventBus</a> infrastructure. With
the latter component, messages exchanged with the Guava <tt>EventBus</tt> can
be transparently forwarded to the Camel routes. EventBus component allows also to route body
of Camel exchanges to the Guava <tt>EventBus</tt>.</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>
for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span
class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-guava-eventbus<span
class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same
version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<h3><a name="GuavaEventBus-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
guava-eventbus:busName[?options]
</pre>
</div></div>
<p>Where <b>busName</b> represents the name of the <tt>com.google.common.eventbus.EventBus</tt>
instance located in the Camel registry.</p>

<h3><a name="GuavaEventBus-Options"></a>Options</h3>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>eventClass</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> If used on the consumer side
of the route, will filter events received from the <tt>EventBus</tt> to the instances
of the class and superclasses of <tt>eventClass</tt>. Null value of this option
is equal to setting it to the <tt>java.lang.Object</tt> i.e. the consumer will
capture all messages incoming to the event bus. This option cannot be used together with <tt>listenerInterface</tt>
option. </td>
</tr>
<tr>
<td class='confluenceTd'><tt>listenerInterface</tt></td>
<td class='confluenceTd'><tt>null</tt></td>
<td class='confluenceTd'> <b>Camel 2.11:</b> The interface with method(s)
marked with the <tt>@Subscribe</tt> annotation. Dynamic proxy will be created
over the interface so it could be registered as the <tt>EventBus</tt> listener.
Particularly useful when creating multi-event listeners and for handling <tt>DeadEvent</tt>
properly. This option cannot be used together with <tt>eventClass</tt> option.</td>
</tr>
</tbody></table>
</div>


<h3><a name="GuavaEventBus-Usage"></a>Usage</h3>

<p>Using <tt>guava-eventbus</tt> component on the consumer side of the route
will capture messages sent to the Guava <tt>EventBus</tt> and forward them to
the Camel route. Guava EventBus consumer processes incoming messages <a href="http://camel.apache.org/asynchronous-routing-engine.html"
class="external-link" rel="nofollow">asynchronously</a>. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
SimpleRegistry registry = <span class="code-keyword">new</span> SimpleRegistry();
EventBus eventBus = <span class="code-keyword">new</span> EventBus();
registry.put(<span class="code-quote">"busName"</span>, eventBus);
CamelContext camel = <span class="code-keyword">new</span> DefaultCamelContext(registry);

from(<span class="code-quote">"guava-eventbus:busName"</span>).to(<span class="code-quote">"seda:queue"</span>);

eventBus.post(<span class="code-quote">"Send me to the SEDA queue."</span>);
</pre>
</div></div>

<p>Using <tt>guava-eventbus</tt> component on the producer side of the route
will forward body of the Camel exchanges to the Guava <tt>EventBus</tt> instance.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
SimpleRegistry registry = <span class="code-keyword">new</span> SimpleRegistry();
EventBus eventBus = <span class="code-keyword">new</span> EventBus();
registry.put(<span class="code-quote">"busName"</span>, eventBus);
CamelContext camel = <span class="code-keyword">new</span> DefaultCamelContext(registry);

from(<span class="code-quote">"direct:start"</span>).to(<span class="code-quote">"guava-eventbus:busName"</span>);

ProducerTemplate producerTemplate = camel.createProducerTemplate();
producer.sendBody(<span class="code-quote">"direct:start"</span>, <span class="code-quote">"Send
me to the Guava EventBus."</span>);

eventBus.register(<span class="code-keyword">new</span> <span class="code-object">Object</span>(){
  @Subscribe
  <span class="code-keyword">public</span> void messageHander(<span class="code-object">String</span>
message) {
    <span class="code-object">System</span>.out.println(<span class="code-quote">"Message
received from the Camel: "</span> + message);
  }
});
</pre>
</div></div>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Guava+EventBus">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=27849882&revisedVersion=5&originalVersion=4">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Guava+EventBus?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message