Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.

Twitter Websocket Example

Available as of Camel 2.10

This example is located in the Camel distribution at examples/camel-example-twitter-websocket.

There is a Twitter Websocket Blueprint Example for OSGi Blueprint users.

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.
As usual the code in Camel is very simple. All it takes is roughly

  from("twitter://search?...")
    .to("websocket:camel-tweet?sendToAll=true")

This example is already configured using a testing purpose twitter account named 'cameltweet'. And therefore the example is ready to run out of the box.

This account is only for testing purpose, and should not be used in your custom applications. For that you need to setup and use your own twitter account.

How to use my own twitter account

To use twitter, you need a twitter account which have setup an application to be used.
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.
The same applies for this example. You can read details about how to setup a new twitter application at the Camel Twitter documentation.

In your Twitter settings under the Apps menu, it will list your approved applications. For example I created an application named "Camel-Example"
which is now listed as approved with read-only access.

When you have created an application, you get a number of details back from twitter
which you need to use the twitter component. Enter these details in the source code at:
src/main/java/org/apache/camel/example/websocket/CamelTwitterWebSocketMain.java

You will need to compile this example first:

mvn compile

To run the example type

mvn exec:java

Then open a browser to see live twitter updates in the webpage

http://localhost:9090/index.html

To stop the example hit ctrl + c

When the application runs, the webpage should automatic update with new tweets. A screenshot below illustrates what you would see:

See also

© 2004-2015 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram