I am currently writing a forum web-application using Spring MVC. I'm just a beginner at Spring and have only been working with it for about 1 week now.
I need to implement push notifications. Here is the scenario: User A logs in and creates a post. User B comments on User A's post while User A is still logged in. User A receives a notification that some user has commented on his post, without his browser refreshing the page.
I need help with sending the notification to User A that User B has commented on his post asynchronously. I have done some research, and found that there is a package called CometD that I can use, but I cannot find any simple tutorials for me to understand.
Can anyone suggest any other packages/way to solve my problem? Or if you have any simple CometD tutorials, that would be great as well.
I am the CometD project lead.
CometD ships with a demo war file that has a built-in chat application that you can use as a basis to understand how CometD works, see https://docs.cometd.org/current/reference/#_installation.
The CometD full reference documentation is here: https://docs.cometd.org.
From experience, I don't recommend using Servlet 3.0 async features to implement a chat, because that will rule out usage of WebSocket.
It's better you rely on frameworks such as CometD that can start with WebSocket (as it is more efficient) and then fallback automatically and transparently to HTTP if WebSocket does not work.
On a similar note, I don't recommend a WebSocket only approach because WebSocket does not work in certain scenarios (for example, mobile networks often do not allow WebSocket traffic), and it's a too low-level protocol so you will have to build your own protocol on top of WebSocket (which is a lot of work and not easy to get right).
CometD provides you with an easy to extend protocol and automatic transport fallback, and has a ton of features (e.g. authorization & authentication and clustering just to mention two).
Have a look at the spring MVC chat sample app for spring MVC 3.2, there is also a spring blog post about it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With