Push Notification in Spring MVC WebApp
Asked Answered
A

2

14

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.

Anhydrous answered 3/1, 2014 at 10:12 Comment(2)
Take a look at Async support(DeferredResult) and the Spring 4 WebSockets support.Alroy
What are you using for your views? JavaScript and jQuery have AJAX GET and POST requests. They might save you. Try thisThunell
H
7

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).

Houseboy answered 4/1, 2014 at 11:15 Comment(2)
Disclaim you're the project leader of CometD ;-) So this answer remains to be subjective.Pau
Your given links are dead.Harsh
F
5

Have a look at the spring MVC chat sample app for spring MVC 3.2, there is also a spring blog post about it.

Fenny answered 3/1, 2014 at 10:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.