camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Twitter Websocket Example
Date Mon, 19 Mar 2012 08:56: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/Twitter+Websocket+Example">Twitter
Websocket Example</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <h2><a name="TwitterWebsocketExample-TwitterWebsocketExample"></a>Twitter
Websocket Example</h2>
<p><b>Available as of Camel 2.10</b></p>

<p>This example is located in the Camel <a href="/confluence/display/CAMEL/Download"
title="Download">distribution</a> at <tt>examples/camel-example-twitter-websocket</tt>.</p>

<p>The example is demonstrating how to poll a constant feed of twitter searches and
publish results in real time using web socket to a web page.<br/>
As usual the code in Camel is very simple. All it takes is roughly</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"twitter:<span class="code-comment">//search?..."</span>)
</span>    .setHeader(<span class="code-quote">"websocket.sendToAll"</span>,
<span class="code-quote">"<span class="code-keyword">true</span>"</span>)
    .to(<span class="code-quote">"websocket:camel-tweet"</span>)
</pre>
</div></div>

<p>To use twitter, you need a twitter account which have setup an application to be
used.<br/>
For twitter users, you may be familiar that twitter requires you to grant applications access
to your twitter account, such as twitter for iphone etc.<br/>
The same applies for this example. You can read details about how to setup a new twitter application
at the Camel <a href="/confluence/display/CAMEL/Twitter" title="Twitter">Twitter</a>
documentation.</p>

<p>In your Twitter settings under the Apps menu, it will list your approved applications.
For example I created an application named "Camel-Example"<br/>
which is now listed as approved with read-only access.<br/>
<span class="error">Unable to render embedded object: File (twitter-apps.png) not found.</span></p>

<p>When you have created an application, you get a number of details back from twitter<br/>
which you need to use the twitter component. Enter these details in the source code at:<br/>
  <tt>src/main/java/org/apache/camel/example/websocket/CamelTwitterWebSocketMain.java</tt><br/>
in the constant fileds, by replacing the values "INSERT HERE".</p>

<p>You will need to compile this example first:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn compile
</pre>
</div></div>

<p>To run the example type</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn exec:java
</pre>
</div></div>

<p>Then open a browser to see live twitter updates in the webpage</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
http:<span class="code-comment">//localhost:9090</span>
</pre>
</div></div>

<p>To stop the example hit ctrl + c</p>

<p>When the application runs, the webpage should automatic update with new tweets. A
screenshot below illustrates what you would see:<br/>
<span class="error">Unable to render embedded object: File (gaga.png) not found.</span></p>

    </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/Twitter+Websocket+Example">View
Online</a>
              |
       <a href="https://cwiki.apache.org/confluence/display/CAMEL/Twitter+Websocket+Example?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message