camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Liguori (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache Camel > CouchDB
Date Wed, 11 Sep 2013 11:24:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/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/CouchDB">CouchDB</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~gliesian">Robert
Liguori</a>
    </h4>
        <br/>
                         <h4>Changes (1)</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>{code} <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">couchdb:http://hostname[:port]/database?[options...]://name[?options]</span>
<span class="diff-added-words"style="background-color: #dfd;">couchdb:http://hostname[:port]/database?[options]</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="CouchDB-CamelCouchDBcomponent"></a>Camel CouchDB component</h2>

<p><b>Available as of Camel 2.11</b></p>

<p>The <b>couchdb:</b> component allows you to treat <a href="http://couchdb.apache.org/"
class="external-link" rel="nofollow">CouchDB</a> instances as a producer or consumer
of messages. Using the lightweight LightCouch API, this camel component has the following
features:</p>

<ul>
	<li>As a consumer, monitors couch changesets for inserts, updates and deletes and publishes
these as messages into camel routes.</li>
	<li>As a producer, can save or update documents into couch.</li>
	<li>Can support as many endpoints as required, eg for multiple databases across multiple
instances.</li>
	<li>Ability to have events trigger for only deletes, only inserts/updates or all (default).</li>
	<li>Headers set for sequenceId, document revision, document id, and HTTP method type.</li>
</ul>


<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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-couchdb&lt;/artifactId&gt;
    &lt;version&gt;x.x.x&lt;/version&gt;
    &lt;!-- use the same version as your Camel core version --&gt;
&lt;/dependency&gt;
</pre>
</div></div>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
couchdb:http://hostname[:port]/database?[options]
</pre>
</div></div>

<p>Where <b>hostname</b> is the hostname of the running couchdb instance.
Port is optional and if not specified then defaults to 5984.</p>

<h3><a name="CouchDB-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>deletes</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> document deletes are published as events </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>updates</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> document inserts/updates are published as events </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>heartbeat</tt> </td>
<td class='confluenceTd'> <tt>30000</tt> </td>
<td class='confluenceTd'> how often to send an empty message to keep socket alive in
millis </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>createDatabase</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> create the database if it does not already exist </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>username</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> username in case of authenticated databases </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> password for authenticated databases </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="CouchDB-Headers"></a>Headers</h3>

<p>The following headers are set on exchanges during message transport.</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CouchDbDatabase</tt> </td>
<td class='confluenceTd'> the database the message came from </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CouchDbSeq</tt> </td>
<td class='confluenceTd'> the couchdb changeset sequence number of the update / delete
message </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CouchDbId</tt> </td>
<td class='confluenceTd'> the couchdb document id </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CouchDbRev</tt> </td>
<td class='confluenceTd'> the couchdb document revision </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CouchDbMethod</tt> </td>
<td class='confluenceTd'> the method (delete / update) </td>
</tr>
</tbody></table>
</div>
</div>

<p>Headers are set by the consumer once the message is received. The producer will also
set the headers for downstream processors once the insert/update has taken place. Any headers
set prior to the producer are ignored. That means for example, if you set CouchDbId as a header,
it will not be used as the id for insertion, the id of the document will still be used.</p>

<h3><a name="CouchDB-MessageBody"></a>Message Body</h3>

<p>The component will use the message body as the document to be inserted. If the body
is an instance of String, then it will be marshalled into a GSON object before insert. This
means that the string must be valid JSON or the insert / update will fail. If the body is
an instance of a com.google.gson.JsonElement then it will be inserted as is. Otherwise the
producer will throw an exception of unsupported body type.</p>

<h3><a name="CouchDB-Samples"></a>Samples</h3>

<p>For example if you wish to consume all inserts, updates and deletes from a CouchDB
instance running locally, on port 9999 then you could use the following:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("couchdb:http://localhost:9999").process(someProcessor);
</pre>
</div></div>

<p>If you were only interested in deletes, then you could use the following</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("couchdb:http://localhost:9999?updates=false").process(someProcessor);
</pre>
</div></div>

<p>If you wanted to insert a message as a document, then the body of the exchange is
used</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("someProducingEndpoint").process(someProcessor).to("couchdb:http://localhost:9999")
</pre>
</div></div>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CAMEL">Stop
watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change
email notification preferences</a>
</div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/CouchDB">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=30148793&revisedVersion=7&originalVersion=6">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/CouchDB?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message