Fork me on GitHub

28 May 2010

Grails Spring Events Plugin

Following on from my last post I've developed a Grails plugin that packages the asynchronous events behaviour up and adds some extra useful functionality.

In addition to the asynchronous event processing the plugin gives you:
  • A publishEvent method attached to all domain classes, controllers and services.
  • A Hibernate session bound to the listener thread for the duration of the notification so that listeners can access lazy-loaded properties, etc.
  • The ability to have a "retry policy" for certain types of failed notifications on individual listeners. This is particularly useful for listeners that do things like invoking external web-services that may be periodically unavailable.

To install the plugin just use:
grails install-plugin spring-events

The code and some more detailed documentation is on GitHub. I'll be migrating the docs to the plugin's page on soon.


Eric Fung said...

Thanks for this. I've been struggling with how to resolve the LazyInitializationException errors I get with Hibernate when my ApplicationEvent listener tries to use lazily loaded objects. I adapted your Grails code for use with regular Spring and it's working great!

Altair said...

Is there a way to make a particular event synchronous?

For most of my events, having them asynchronous is desirable, however for a select few synchronous execution is required.

I suspect that this would require me to create my own publishing service, as well as changes to the plugin itself (so that it did not use the taskExecutor when notifying listeners).

Metamorfosis said...

Pelatihan SDM is a network marketing and training information or training an employee who has worked with many consulting firms and training institutions.
pendidikan dan pelatihan sdm, pelatihan akuntansi, sales marketing, manajemen bisnis, administrasi kantor, lembaga training motivasi, pelatihan sumber daya manusia, training manajemen, training sdm, informasi training, pusat pelatihan, pelatihan rumah sakit, training provider jakarta, training jakarta, training consultant jakarta, training center,