Announcement Announcement Module
No announcement yet.
transactional message publishing from a grails service Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • transactional message publishing from a grails service

    Hi all,

    My project is a groovy/grails project. In essence, some of my groovy transactional service instance-methods will be doing the message publishing, with fire-and-forget semantics.

    For those unfamilliar with Grails, a Grail Service is pretty much like a java bean annotated with @Service stereotype and @Transactional (propagation:required). So I think that, provided that the grails framework is doing its transaction demarkation in a really weird way, a grails service method will behave just like an normal Java class method. Maybe I should have even left grails out of the picture here

    In those 'do-some-work and publish a message'-scenarios, I need to make sure that a message only gets published after a regular ORM transaction has been committed. The consumption of that message will be done asynchronously, and therefore in a different transaction which is fine. In time, I will probably add JMS or AMQP to do this properly and I know Spring Integration will help me out there too.

    So before I dive in I would like to do some fact checking here...

    -1. I assume that I can declare an interface in Java (maybe even in groovy but that's hardly important) that I configure to be a Spring Integration Gateway and inject that into my grails service. Nothing different from a standard java project here. Is this correct?

    -2. Can I use spring integration to make sure that the message only gets published *after* the transaction on my service method has been committed? If I read the SI manual (chapter 27), it seems to me that my usecase falls in the 'User process' category. Further reading almost leads me to believe that what I want is what is provided by SI automagically Is that correct? If not, what other solution pattern should I consider?

    Hope somebody can help me out
    Last edited by mirror303; Jan 28th, 2011, 08:54 AM. Reason: added some pointers for those unfamiliair with Grails

  • #2
    To answer my own question: yes it all works


    • #3
      Hi Hans,

      I am also working on groovy/grails project and currently learning on how to make the events transactional - like the events/messages should be published only when a status change is successfully made (when GORM transaction is committed).

      I have two operations:
      jmsTemplate.send() -- template is defined through SI.

      Will spring automatically handle operations in single transaction?
      If save() fails, message will not be sent? If yes, can I assume that save() will be added to current transaction (if exists or new one is created) and send() is added to transaction? If no, how can I achieve that?
      Any kind of help is appreciated.

      Thank you,