Hopefully you will have seen our webinar which gave an insight into the type of applications that can be built rapidly with Apama Community Edition – if not – you can see it here. This post serves as an aid alongside that, briefly describing the application that was shown and supplying links to help you get started so that you can download, run and begin expanding and changing it to suit your needs.
The project in question is TwitterAnalysis. This contains two different applications; a TwitterAnalyzer application and an optional TwitterMonitoring background application.
Within Apama Designer both of these can be run from the same project using multiple run configurations, that accompany the project. These run configurations differ by defining what needs to be injected for each application, and ensuring that both correlators do not try to start on the same port. They are both independent applications and can be run individually for their respective purposes.
The main application is the TwitterAnalyzer application. This streams from Twitter all tweets relating to a particular phrase, in this case “Apama Community Webinar”. These tweets are converted to and sent as events to the monitor which then examines them. Using our streaming analytics, certain criteria are defined so that it can decide when a reaction Tweet should be sent. In our example it requires 3 relevant tweets within 15 seconds of each other before we react.
As discussed in the webinar this decision criteria can be easily extended to be made much more complex (or indeed simplified) along with other specific requirements to suit your application needs.
For example using streams and Apama’s built in aggregates, you could determine the count of all tweets received within a 10 second window as shown below:
stream mytweetInfoStream := all TweetInfo();
from t in mytweetInfoStream within 10.0 select com.apama.aggregates.count() as totalRecentTweets
log "Received count in timed window ..." + totalRecentTweets.toString() + " for " + phrase at INFO;
The TwitterMonitoring application is a visual aid only. It will display all tweets that relate to a certain phrase; in this case “Apama Community Webinar” in the top section of the dashboard and all tweets that relate to a reaction Tweet (sent from the TwitterAnalyzer application), in the bottom section of the dashboard. Thus we can use it to determine if our ‘Analyzer’ is reacting appropriately.
Within the project, both applications use a connectivity plugin which acts as the interface to Twitter. To find out more about connectivity plugins please see the following blog posts:
For projects that require a dashboard, Apama Designer will automatically run with the default Apama Dashboard Viewer, which is a “client-side” java application. However, if instead you wish to deploy your dashboard as an HTML page like the version seen in the webinar you can find out how to do so by following the Apama documentation under deploying dashboards (Building and Using Dashboards -> Dashboard Deployment) to find out how to run and interact with a remote dashboard.
Running the project
In order to run a newly downloaded version of this project you must enter your own Twitter credentials, and you must also create the jar file that the project expects to use.
Creating the Jar file
To create the jar file for the project’s connectivity bundle you must do a clean build of the project and then right click on the
.jardesc file and select the ‘createJar’ option.
.jardesc file details where to store the jar, and in our case it is the Apama work directory, so please check the path is appropriate for your system.
In order to connect to Twitter from any application, you must first register the application on your Twitter account. You can do this at https://apps.twitter.com/
Some details on how to go about setting this up correctly can be found at the following links for example:
Within our project we have two separate applications, and to avoid Twitter login issues as much as possible, these both use different authentication credentials.
You do not need two separate Twitter accounts to achieve this – you simply add another app under your current Twitter account as described above.
When you have access to the Twitter app authentication credentials, you can update the respective
.properties files in the project depending on which application you wish to run (or for both).
For example you will find the TwitterAnalyzer properties file under Connectivity and Adapters -> User Connectivity (…) -> TwitterAnalyzer -> TwitterAnalyzer.properties in the project in Designer.
If you would like to get hold of this application you can download it from here – TwitterAnalysisApp-188.8.131.52.
If you have any questions, something you didn’t get a chance to ask during the webinar, or perhaps something you’ve thought of since, please feel free to ask such questions on the forum http://www.apamacommunity.com/community-forums/
We look forward to hearing what ways you’ve expanded and tweaked this application for your own uses, so please do get in touch.
We hope you found the webinar and related assets useful on your path of starting to learn how to build solutions using Apama. Twitter is just one example of a source of events, and a destination for events, but of course there are many other possibilities both with social media system and many other domains.
Utilities and samples shown here are not official parts of the Software AG products. These utilities and samples are not eligible for technical support through Software AG Customer Care. Software AG makes no guarantees pertaining to the functionality, scalability, robustness, or degree of testing of these utilities and samples. Customers are strongly advised to consider these utilities and samples as “working examples” from which they should build and test their own solutions