1

I have an app written with JSF and Spring using JPA+Hibernate which is running on a Glassfish4 server.
Right now I have an Observer pattern which is listening for some Postgresql events. Let`s say that on very insert in some table my listener is triggered.

Everything is OK now because I have only one server but I want to migrate to a cluster (4 nodes) setup, so there will be a problem because when an row will be inserted my trigger will be fired 4 times.

What is the common approach when you have to deal with this kind of things ?

I was thinking to keep a database table and when an event appears to check if the event id is not already in the table, but I think here I will have some concurrency issues and I`ll have some rolled back transactions.

Any idea how I can elegantly deal with this ?

  • Is this application also the generator/publisher of these records/events? Or is that part of a different application? Do you have control over the publisher/generator? Are the records created purely to emit an event, or do they have intrinsic value besides invoking an action somewhere else in your system? – thexacre Apr 7 '15 at 8:26
  • No, the generator is a PBX system. I have to know when a phone call was finished (that is the trigger) in order to start creating some permission for the users to see that call (users from my java app). – Videanu Adrian Apr 7 '15 at 8:51
  • RE:my trigger will be fired 4 times - I'm not entirely clear on the concern here: if you have 4 separate VMs, connected to the same DB, won't you want the notification to be available in all 4 VMs? – kolossus Jun 10 '15 at 16:33
  • No I do not, as the first VM that is triggered has to process that event and save the result in DB. The remaining vm`s should just ignore it. – Videanu Adrian Jun 11 '15 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.