How to send a notification to all registered users

I have Spring MVC, Spring Thymeleaf, Spring Security and Hibernate on a MySQL application. My task is to notify all registered users if there is new data for the page being viewed, so that users can update and receive a new data set.

I assumed that I could store all registered users in an ApplicationScope session, and then somehow notify them. But I had never done this before and did not know how safe it was.

Can anyone suggest any idea on how to do this?

+7
source share
2 answers

You need a push / pull architecture (to initiate sending messages from the server side). None of the Spring frameworks you use can do this. Departure Atmosphere https://github.com/Atmosphere/atmosphere

Then, when new data is saved (your DAO level can trigger this), you can simply enter a new message through the Atlmosphere servlet to all subscribers. Atmosphere uses “channels”, so you can use the predefined channel name for the users of the page, and all users will receive a message. You can also provide the Atmosphere surfing servlet with Spring security so that unauthenticated users will not be able to receive notifications.

+3
source

Based on the comments above, you can implement a pull architecture with something like this:

Store all events in a central place, accessible for all sessions (Singleton, Database, etc.). Verify that a consistent identifier exists.

Save the last event identifier received in the session. As needed, request events with identifiers that exceed the last identifier stored in the session.

Hope this helps.

+1
source

All Articles