Following on from my previous 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 grails.org soon.