Tuesday, 14 February 2012

Twittering new Posts using Mule Studio and ION

I must admit that personally I am not really much into social media and rarely find myself twittering or updating my status. However anyone must admit that they are valuable channels to pass on information and want to start tweeting every time I publish a new post. So this was a great opportunity to try out the new Mule Studio and MuleION and deploy this simple application.

I was involved in the testing of the earlier Mule Studio releases and must admit that this has been polished quite a lot. It is quite easy to create a Mule Project and deploy it to Mule. Another nice feature is that it is easy to run the application in Mule and also, every time you save the configuration, the mule application is reloaded. It is also just as easy to deploy to MuleION (Mule's cloud offering), just a simple click. Now lets take a quick look at the application:

Blog Notifier Flow from Mule Studio
  1. Using the poll component and an http endpoint we can poll the atom url of this blog which is http://integrationcocktail.blogspot.com/atom.xml
  2. The http receiver returns a stream which we need to transform into a String so that then we can split.
  3. We use the splitter in order to split the atom.xml into the different blog entries. Actually, we only care of the entry link since it contains the URL and the title. We use the xpath expression /atom:feed/atom:entry/atom:link[@rel='alternate']. We also need to add the atom namespace to the namespace manager.
  4. Here we simply log the information of the entry being processed  : Processing post  title=#[xpath://@title] and path=#[xpath://@href]
  5. Here we check of the entry is already in MongoDB. If it is present already, then this entry has already twittered, otherwise it still needs to be twittered. We use the count-objects-using-query-map method and pass as parameter the path. The target of the enrichment is #[header:existsInMongoDb] and the source is the expression #[groovy:payload>0]. So existsInMongoDb header is true if Mongo DB returned a count larger than 0.
  6. When the header evaluator with expression existsInMongoDb=true returns true, then we simply log that this entry has already been processed: Post already twittered:title=#[xpath://@title] and path=#[xpath://@href].
  7. Otherwise we log that we are about to twitter: Twittering:title=#[xpath://@title] and path=#[xpath://@href]
  8. We update the status with the title and the path
  9. We insert the title and the path into Mongo DB since it has now been published
Finally, to upload to ION, you can do it very easily from the IDE.

The following is the full configuration:

Mule Studio is quite mature, and it was fun to just drag and drop what you want... most of the time. There are obviously some items missing, for example, the namespace manager is not part of the xml elements, so I had to do that in the xml configuration mode, which did not know about it either. Another slight disappointment was that the sources are not attached, which will make it impractical to debug. I would also have preferred to have the project be a maven project, but then, I do agree that not everybody likes maven so it does not make sense to tie the IDE with any particular build tool. I guess the next step would be to find a way for Mule Studio to complement my development approach which focuses more on automated tests rather then running the application in a server and find a way for Mule Studio to play nice with maven. Once I have that figured out I will probably start using Mule Studio exclusively when developing Mule applications since it makes it so easy to deploy the applications to a standalone server or upload it to ION.

1 comment: