Search code examples
springspring-bootwebsocketspring-websocketspring-messaging

How many endpoint and topic need for Direct ,Group,Channel in Spring Websocket?


I want to write application that make messaging between users, Messages that send between users is in 3 types

  1. Direct
  2. Channel: just send from admin
  3. Group

My application will save messages in RDBMS. When new message send and receiver user is online ,my app will notify to user that new message receive , I decided to write my application using Spring Websocket and Stomp .My application using spring security and and i want show online users in group and direct for each other member my question is know how many endpoint and broker i need ? and how can do that.

Update:

My application is similar gitter and slack , when user login messages may receive from direct or group or channel. when i switch between users and group or channel i will unsubscribe from last and subscribe to user or group that i chat in .i dont know subscribe and unsubscribe is correct or just one subscribe for all . is this usage correct or not?

chatSocket.subscribe("/user/exchange/direct/chat.message/{userId}", function(message) {});


chatSocket.subscribe("/topic/group/chat.message/{groupId}", function(message) {});

Solution

    • For direct messages, use user destinations.
    • For messages that can only be sent by admins, restrict publishing to users with that role and allow other users to subscribe (with Spring Security)
    • If you want to broadcast messages, use broker destinations (or app destinations if you need to add some login)

    An option to store messages could be adding a channel interceptor. Make users subscribe to an app destination when the websocket connection is established and send the stored messages sent while he was online.

    This sample application could give you some hints: https://github.com/salmar/spring-websocket-chat