Lyndsey has posted 139 posts at DZone. View Full User Profile

Book Giveaway: Grails In Action Exclusive Chapter Download

  • submit to reddit

DZone and Manning Publications have partnered to bring you an exclusive chapter from 'Grails in Action' (by Glen Smith and Peter Ledbrook). This chapter covers what messaging is, how it works, and how it aids scalable architectures. It describes how to implement queues and topics with a popular JMS server. You'll also learn how scheduling is implemented in grails and more. 

Understanding Messaging and Scheduling

In this chapter, we’ll keep you in that enterprise headspace, but we’ll look at sending intra-application messages. In particular, we’ll examine how different components in an application can communicate internally while different events in the application’s lifecycle unfold. One of the most popular ways of doing that is via messaging queues, an architecture sometimes referred to as message-oriented middleware (MOM).

If you’ve been around enterprise circles for a while, you’ve probably used or heard of MOM architectures. You might be thinking it’s some kind of heavyweight old-school technology that just won’t die. Nothing could be further from the truth. In fact, with the birth of service-oriented architecture’s (SOA’s) Enterprise Service Bus (ESB), and the rise of massive Web 2.0 social networking sites, we’re experiencing an explosion of interest in messaging architectures.

You might be wondering why these styles of architecture have had such a resurgence in recent years. From Twitter to Digg to LinkedIn, if you look behind any of today’s big Web 2.0 applications, you’ll find that they’re backed by an extensive messaging infrastructure. These messaging architectures are so prevalent at high-volume sites for three reasons:

  • They lead to loosely coupled architectures, which means you can replace parts of your infrastructure without any client downtime.
  • They have high scalability—you can add more components to process work on your queue.
  • They offer a reliable transport that ensures your messages and transactions don’t get lost in the system.

In this chapter, we’ll add a messaging system to Hubbub so we can create a link between Hubbub and Jabber, a popular instant messaging (IM) system. By the time we’re done, you’ll be able to post messages to your Hubbub account via your IM client, and we’ll also bridge the other way so you can be notified of your friends’ Hubbub posts in your IM client. Along the way, you’ll learn the ins and outs of all the common messaging scenarios and get some ideas on how to apply them to your current projects.

But messaging isn’t the only asynchronous game in town. In many situations, a lightweight scheduling solution is all you need. Kicking off a daily backup? Sending out daily digest emails? Regenerating your full text index? Every developer needs to deal with these kinds of scheduled events occasionally, and Grails offers a robust and easily configurable scheduler based on the popular Quartz framework. We’ll look at the different ways you can schedule jobs—how to write daily-digest type jobs, how to turn them off and on while your application is running, and how scheduling works in clustered environments.

We’ll get into the details of scheduling a little later. For now, let’s sink our teeth into some messaging.

Click here to download the entire chapter

The above introductory excerpt was taken from Grails in Action, published in May 2009. It is being reproduced here by permission from Manning Publications. Manning early access books and ebooks are sold exclusively through Manning. Visit the book's page for more information.

ManningChGrailsiACH12.pdf694.42 KB
book_contest_grailsinaction.jpg29.21 KB
Published at DZone with permission of its author, Lyndsey Clevesy.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Douglas Bailey replied on Fri, 2009/07/31 - 1:20pm

I have used the Quartz and JMS plugins. They really help make building a app that much easier. Being able to schedule jobs and being able to have work done asynchronously take Grails from a good solution for little apps to a complete solution for enterprise level applications.

tomas lin replied on Sat, 2009/08/01 - 8:51am

I've been working with Grails for about a year and a half. It has its rough edges but I have never been so productive with a Java web framework the same way I have been with Grails before. It has a very supportive and forward-thinking user community, and the way you can easily integrate third party java libraries easily via the robust plugin infrastructure ( 250+ plugins! ) is just mind blowing.

If you're suffering from Java fatigue, you owe it to yourself to check out Grails.

Peter Ledbrook and Glen Smith are very well known in the community. Their credentials are impeccable. Glen Smith has done a lot of development with Grails and hosts the Grails podcast, Peter works for SpringSource and has contributed to many plugins like JSecurity. The book is packed with knowledge but reads more like a crazed conversation with a deranged guru ( in a good way ) than a tech manual. I highly recommend it.

Oh, DZone, please fix your commenting system. It returns service unavailable whenever it thinks a message is spam.

Jonathan Garay replied on Sat, 2009/08/01 - 12:30pm

Goovy makes me re-think the way of i develop on java, Groovy is the simples way to develop agile and productivity in mind with out lost the "Enterprice Java" stigma

Pramatr Ramatr replied on Sun, 2009/08/02 - 3:57am

Since starting my Grails learning experience a few weeks ago I’ve gone from knowing absolutely nothing about it to building a complete application very quickly. After finding plug-ins for many of the tasks I wanted (over 250 available), I’ve implemented the logic I need and let the tool do the rest of the heavy lifting work which led to some very productive coding.

After tweaking grails default scaffolding, I managed to get a fully functional demo application working in a few hours and managed to clock up several hours of development without a single server restart (this was only cut short by the need to sleep). This was made possible by a feature within Grails known as auto reloading, which confirmed to me, when working with Java I'm sick of restarting my server!

Even though I'm still learning the framework and there is very much I don't know, I'm making real progress which is made evident in the artefacts I've produced. Grails has so far provided a really impressive and effortless development experience. I really love it when you find technology which just seems to work and does exactly what you expect it to do. Lately I really have been having fun with Grails and can't remember the last time I was so productive.

If you don't believe the hype try it out for yourself, it really does just work!

Ildar Karimov replied on Sun, 2009/08/02 - 6:37pm

Groovy/Grails is just like IntelliJ IDEA for me - 'develop with pleasure' is simply the best description of the development process with g/g!

Stephen Robillard replied on Thu, 2009/09/03 - 11:47pm

I would love to read this since I have decided that grails will be the next thing I teach myself. Reading this would go aalong way to get me up and running in short order.

Phon xay replied on Wed, 2009/09/09 - 9:20pm

I just recently discovered grails via a reading on rails framework clone article which I don't remember the website now. But to my understanding I need to learn to Groovy in order for me to be efficient in Grails so I've bought ebook on Groovy, Grails in Action would be a great addon for me to take up on when I have deeper understanding groovy. Thank phon

Sudhakar Ramasamy replied on Thu, 2009/09/24 - 8:49pm

I used rails for a project recently. But the learning curve of a new web framework (rails) and a new language (ruby) was a little too much for me. Instead groovy/grails is looking like an easier transition from Java land. If the free copy is still up for grabs I'd love to get one.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.