Notification between Java EE components

纵然是瞬间 提交于 2019-12-22 13:53:10

问题


I have a design problem .

My application has multiple Java EE components ,In simple terms one acts as a service provider(Non UI) and others are consumers(UI webapp) .

The consumer gets the configuration data from the service provider(this basically reads the data from DB) during the start up and stores it in the Cache.

The cache gets refreshed after periodic time to reflect any changes done at the database.

The Problem

Apart from the cache refresh, I also want to notify the consumers when someone changes the DB that configuration has been changed please reload it.

What notification mechanisms can I use to achieve this?


回答1:


I would go with JMS topics/queues. The producer sending a "REFRESH_CACHE" message on a topic and all consumers listening to this




回答2:


I would use a topic for it. When the database changes you can send a message to the topic and all clients listen to it, can show a message.




回答3:


Take a look at the Observer design pattern. You can store consumers in a list and notify them when something interesting happens.




回答4:


You may need OBSERVER pattern.
It notifies the consumers (your UI apps) using Callback. You can use JMS for notifications.



来源:https://stackoverflow.com/questions/2407159/notification-between-java-ee-components

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!