JBoss Fuse on OpenShift: How to Connect to Twitter

In this tutorial you will use the Twitter connection example included in JBoss Fuse on OpenShift to create a simple connection to poll a constant feed of Twitter, listen for a keyword and then publish the results in real time to a log. You will learn how to modify the key word and save your changes so you can listen for a key word of your choice. And once the connection is made we will show you how to monitor this connection.

This tutorial begins after you have installed the Fuse cartridge and logged into the Fuse Management Console. If you wish to learn about that step, please check out the Getting Started page.

Create a container for the Twitter example

Before you start this example check that you have a free gear in your OpenShift account because you will use the Fuse Management Console to start up a new application running in a new gear.

Log into the Fuse Management Console and start at the Runtime area in the Fabric perspective of the Management Console. You will see a list of your existing containers.

We need to create a new container to run the example so over on the left side of the screen is the “Create” button and clicking it will take us to the create container page. Make sure the container type is set to “OpenShift”. Next you will need to give the container a name. Each container in Fuse requires a unique name – I chose “mytwitter”.

If you haven’t previously, you will need to provide your OpenShift user credentials so the management console can access a new gear for you. You should only have to do this once as the console remembers these credentials. Click “Log in to OpenShift”. Next select the gear size you want this application to run in. A small gear should work just fine for this tutorial. Note that the “Create and Start Container” button has turned green as the management console has recognized that you’ve provided enough information to create a new container.

At this point we need to instruct Fuse what to run in this new container and to do that we’re going to associate a profile to the container. To do this we will select a profile from the list of profiles on the right. (Quick note: the management console will alter its layout based on your screen resolution and real estate. So you may have this list of profiles further down the screen underneath the container details.) The Twitter profile is in the Example/Camel folder but an easier way to find it is to use the search tool at the top of the list. Typing “tw” should bring it up right away.

Check the box next to the profile and then click the “Create and Start Container” button to the left. Fuse will begin to provision this container by accessing a free gear of the size you specified, installing fuse and the selected Twitter profile. Depending on the gear size you’re running the management console this could take anywhere from a few seconds to a minute or so. You can monitor progress in the Runtime view listing the containers. Or you can click on your new container and monitor progress from the detail view. In that view you can watch the server status and the provision status. Once you see “running” and “success” in those two lines, you’re ready to go.

Exploring the Twitter application

To look into the new application click the open button. If you’re asked for a user name and password use “admin” and the password you were given when you started up the Fuse cartridge for the first time.

After clicking open you will see the logs for the container you’ve just started. The application is already monitoring Twitter for the default keyword “camel” so you will see instances in the log of Tweets that use “camel”.

Fuse has detected that Camel is running in this container so the dynamic management console has added a “Camel” tab in this view. Clicking on it gives us details about the camel applications that are running in this container. Right now there is only the twitter example. Click on the “twitter-demo” route to see more information about what’s happening with that route. Notice that the numbers in these screens are updating in real time as people use the keyword “camel” in tweets.

Click on “Diagram” in the upper middle of the screen and you can see a visual representation of the route – it’s a pretty simple one. The numbers on this view also update in real time.

Changing the keyword

By now I’m sure you’ve noticed that “camel” isn’t the fast trending term on Twitter. So let’s change the keyword to something that will generate a lot more activity. We can do that by clicking on the twitter profile on the left of the screen which takes us into the wiki that is part of the management console.

When we first come to this view the Read.me file is displayed which shows you the command line method for running the example. Scrolling down the read.me file there are instructions on how to change the keyword. You need to edit the file io.fabric8.examples.camel.twitter.properties. And we can do that through the console by going back up to the list of files in this profile, finding that file and clicking on it.

This brings us to a view of that file and if you look on line 5 you can see where the twitter.keywords value is set to “camel”. To change that value all you have to do is go over the right hand side of the console and click “Edit”. Then change the keyword to something more popular on Twitter – “iPad” or “bieber” for example – and click “Save”.

Fuse detects that there has been a change to the profile and automatically re-provisions any container running that profile and it does it in real time. So when we go back to the log screen we can see updates in the log where the new keyword appears – assuming we chose something popular.

And there you have it. In this tutorial you’ve used the included examples to build a simple route to connect to Twitter and poll it for a keyword.

Comments are closed.