camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Websocket
Date Sun, 25 Mar 2012 13:54: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/Websocket">Websocket</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <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" >{div:class=confluenceTableSmall} <br>||
Key|| Description || <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{WebsocketConstants.SEND_TO_ALL}}
| Sends the message to all clients which are currently connected. <span class="diff-added-words"style="background-color:
#dfd;">You can use the {{sendToAll}} option on the endpoint instead of using this header.</span>
| <br></td></tr>
            <tr><td class="diff-unchanged" >| {{WebsocketConstants.CONNECTION_KEY}}
| Sends the message to the client with the given connection key. | <br>{div} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h3.
Endpoint Options <br> <br>The {{WebsocketEndpoint}} can be configured prior to
use <br> <br>{div:class=confluenceTableSmall} <br>|| Option || Default ||
Description || <br>| sendToAll | {{null}} | To send to all websocket subscribers. Can
be used to configure on endpoint level, instead of having to use the {{WebsocketConstants.SEND_TO_ALL}}
header on the message. | <br>{div} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Usage <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Websocket-WebsocketComponent"></a>Websocket Component</h2>
<p><b>Available as of Camel 2.10</b></p>

<p>The <b>websocket</b> component provides websocket <a href="/confluence/display/CAMEL/Endpoint"
title="Endpoint">endpoints</a> for communicating with clients using websocket.</p>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
websocket:<span class="code-comment">//hostname[:port][/resourceUri][?options]</span>
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

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

<p>None.</p>

<h3><a name="Websocket-MessageHeaders"></a>Message Headers</h3>

<p>The websocket component uses 2 headers to indicate to either send messages back to
a single/current client, or to all clients.</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Key</th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>WebsocketConstants.SEND_TO_ALL</tt> </td>
<td class='confluenceTd'> Sends the message to all clients which are currently connected.
You can use the <tt>sendToAll</tt> option on the endpoint instead of using this
header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>WebsocketConstants.CONNECTION_KEY</tt> </td>
<td class='confluenceTd'> Sends the message to the client with the given connection
key. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Websocket-ComponentOptions"></a>Component Options</h3>

<p>The <tt>WebsocketComponent</tt> must be configured prior to use, to setup
host, to act as a websocket server. </p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> Host </td>
<td class='confluenceTd'> 0.0.0.0 </td>
<td class='confluenceTd'> The hostname. </td>
</tr>
<tr>
<td class='confluenceTd'> Port </td>
<td class='confluenceTd'> 9292 </td>
<td class='confluenceTd'> The port number. </td>
</tr>
<tr>
<td class='confluenceTd'> StaticResources </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Path for static resources such as index.html files etc. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Websocket-EndpointOptions"></a>Endpoint Options</h3>

<p>The <tt>WebsocketEndpoint</tt> can be configured prior to use</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> sendToAll </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> To send to all websocket subscribers. Can be used to configure
on endpoint level, instead of having to use the <tt>WebsocketConstants.SEND_TO_ALL</tt>
header on the message. </td>
</tr>
</tbody></table>
</div>
</div>

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

<p>In this example we let Camel exposes a websocket server which clients can communicate
with. The websocket server uses the default host and port, which would be <tt>0.0.0.0:9292</tt>.<br/>
The example will send back an echo of the input. To send back a message, we need to send the
transformed message to the same endpoint <tt>"websocket://echo"</tt>. This is
needed<br/>
because by default the messaging is InOnly. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// expose a echo websocket client,
that sends back an echo
</span>from(<span class="code-quote">"websocket:<span class="code-comment">//echo"</span>)
</span>    .log(<span class="code-quote">"&gt;&gt;&gt; Message received
from WebSocket Client : ${body}"</span>)
    .transform().simple(<span class="code-quote">"${body}${body}"</span>)
    <span class="code-comment">// send back to the client, by sending the message to
the same endpoint
</span>    <span class="code-comment">// <span class="code-keyword">this</span>
is needed as by <span class="code-keyword">default</span> messages is InOnly
</span>    <span class="code-comment">// and we will by <span class="code-keyword">default</span>
send back to the current client using the provided connection key
</span>    .to(<span class="code-quote">"websocket:<span class="code-comment">//echo"</span>);</span>
</pre>
</div></div>

<p>This example is part of an unit test, which you can find <a href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketRouteExampleTest.java"
class="external-link" rel="nofollow">here</a>. As a client we use the <a href="/confluence/display/CAMEL/AHC"
title="AHC">AHC</a> library which offers support for web socket as well. </p>

<h3><a name="Websocket-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring
Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting
Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/AHC" title="AHC">AHC</a></li>
</ul>

    </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/Websocket">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=27841331&revisedVersion=4&originalVersion=3">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Websocket?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message