James Strachan and I gave a talk last month at the JFokus conference in Stockholm. And for that conference I had prepared a little example using these new components. Unfortunately there was a problem with the projector and James laptop, so we had to give the presentation with slides only.
So this weekend I found some time again, to polish the example, prepare documentation, and donate the example to the Apache Camel project.
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
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.
We have described this in more details at the Camel twitter documentation.
When you have created an application, you get a number of details back from twitter which you need to use the twitter component. We will get back to this later.
This example is located in the examples directory of Apache Camel 2.10, in the camel-example-twitter-websocket. To run the example you use Maven with the following command: mvn compile exec:java
The example will report error if you have not setup your twitter application. To do that edit the source code in the src/main/java/org/apache/camel/example/websocket/CamelTwitterWebSocketMain.java class.
When successfully setup the applications starts, and you can open a web browser on page http://localhost:9090/
By default we do a twitter search every 2nd second for the word “gaga”. There is usually a lot of people tweeting about Lady gaga :). You can of course change this in the aforementioned source file.
Below is a screenshot of the example in action.
|Live feeds of gaga tweets using Camel in a web browser|
The interesting piece in the source code is that its very easy to setup a websocket client
var location = “ws://localhost:9090/camel-tweet”;
Java Platform, Enterprise Edition is a widely used platform for enterprise server programming in the Java programming language.
This book covers exciting recipes on securing, tuning and extending enterprise applications using a Java EE 6 implementation.The book starts with the essential changes in Java EE 6. Then they will dive into the implementation of some of the new features of the JPA 2.0 specification, and look at implementing auditing for relational data stores.They will then look into how they can enable security for their software system using Java EE built-in features as well as using the well-known Spring Security framework. They will then look at recipes on testing various Java EE technologies including JPA, EJB, JSF, and Web services.Next they will explore various ways to extend a Java EE environment with the use of additional dynamic languages as well as frameworks.At the end of the book, they will cover managing enterprise application deployment and configuration, and recipes that will help you debug problems and enhance the performance of your applications.