This example will show how to send notifications, via web socket, to specific logged-in users (definded by access_token).
Could be useful, for example, if you are trying to implement a real-time user notification system with ReactJS.
Backend:
Open the application.properties
file in websocket-spring and set your own database (in my case I'm using MongoDB). You can change User collect to Entity and repository like your project.
- Java 8
- Maven > 3.0
- Start mongodb database
$ mongod
- Go on the project's websocket-spring folder, then type:
Or, just open Maven project on IDE like IntelliJ IDEA and run
$ mvn spring-boot:run
main method
in Application class - Go on project:s websocket-react folder, then type:
or
$ npm install $ npm start
$ yarn install $ yarn start
-
Launch the application and login into it with one of the following credentials (Username / Password):
- user1 / user1
- user2 / user2
-
Keep a window open on the index and login by user1
-
Open a new private/incognito windows of your web browser and login with user2
-
From this web browser specify target user and click the button to send a fake action: target user will be notified.
Special thanks to azanelli for your great example