I’ve got a Spring MVC, Spring Thymeleaf, Spring Security and Hibernate on MySQL application. My task is to notify to all currently logged in users if there is new data persisted for the page they are viewing so that the users can refresh and get a new set of data.
I was guessing that I could store all the logged in users in an ApplicationScope session and then notify them somehow. But I’ve never done this before and not sure how safe it would be.
Can anyone suggest any idea on how this could be done ?
You need push/pull architecture (to initiate sending messages from the server side). None of the Spring frameworks you use can do that. Check out Atmosphere https://github.com/Atmosphere/atmosphere
Then whenever new data is persisted (your DAO layer can trigger this) you can just push new message via Atmosphere servlet to all subscribed users. Atmosphere uses “channels” so you can use predefined channel name for the page users are on, and all users will get the message. You can also secure Atmosphere servlet with Spring security so unauthenticated users wont be able to get notifications.