Tuesday, 21 February 2012

Serving the Mule Tools XSD using the Apache Rewrite Module and PHP

After I created the NamespaceHandler and XSD for the Integration Cocktail Mule Tools module, I wanted to make the XSD available at the URL http://www.integrationcocktail.org/schema/mule/tools/3.2/mule-tools.xsd so that users of the module will have code completion using any half decent XML editor. I bought the domain and was going to use a simple LAMP server to provide the XSD. It was straightforward enough if I wanted to simply put the XSD file, however I know myself, I will forget to update the XSD file after I will do any form of updates to the file. So why not provide the schema directly from the git repository? So, after years not touching any form of PHP I was going to hack a bit with it.

First I added a .htaccess file to rewrite all requests for .xsd files which do not exist to my php script:

After that all I had to do is create a simple script to proxy. I used PHP cURL library to do the requests and voila, simple enough:

Anybody out there who is creating custom mule modules and as they should, to encourage use, creates a custom namespace, please, do make the XSD available for your fellow developers so that you do not have to stay adding it to the IDE.

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.

Tuesday, 7 February 2012

Book Review: Spring Integration in Action

Spring Integration in Action

Finally I have gotten some time to spend on Spring Integration and started by reading Spring Integration in Action MEAP Edition version 7. It is the first time that I am reading a MEAP Edition so will not be able to accurately compare the book, however, from my point of view, it is already in pretty good shape and the mistakes where minimal.

This book is great for anybody who wants to start delving in the world of integration. The book isn't simply a list of recipes of things you can do with Spring Integration but rather discuss the integration issues in their own right and then describe how you would do it using Spring Integration. The first two parts are quite heavy on theory which is great for beginners however developers who have been doing integration with other tools might want to skim through these chapters and look at the labs. I was quite happy to see the discussion of transaction boundaries discussed as early as Chapter 3 since it is a topic which I feel is sometimes ignored.

The third part starts with a discussion about splitting and aggregating messages then focused more on the different transports. The most interesting part here is the file based collaborative trip diary editor which is described in this section. This lab describes how you can have a collaborative text editor by writing “diffs” to the file system and have multiple clients writing to the same directory and thus working on the same file concurrently.

Personally I found the final part quite interesting. Well, to be honest, I was a bit confused why the chapter about twitter and chatting was not placed in the previous part, but apart from that, the rest is great. I loved the introduction to Spring Batch and the discussion on OSGI & scaling up applications. Something which I found surprising was how easy it is in Spring Integration to monitor the message path. The testing chapter is also quite interesting but I would have moved it earlier in the book since it can help with understanding and explaining.

All in all, this is a great book and can't wait to get the final version. I give this book a score of 4 out of 5 but has the potential to be 5 out of 5 once it is ready.