Sending user-specific messages
So far, we have crafted a relatively rich application using different types of broadcast messages.
For example, when a new comment is written, it's sent to every client. Only the clients actually displaying the relevant image will update anything. But the message was sent nonetheless. Also, when a user enters a new chat message, it's sent to everybody. For these use cases, this solution is fine. WebSockets make the process quite efficient.
But there are definitely scenarios when we want to send a message to just one subscriber. A perfect example we'll pursue in this section is adding the ability to "@
" a user with a chat message. We only want such a message sent to that specific user. What would be even better? If we could do this without ripping up everything we've done so far.
We can start with the ChatController
inside the chat
microservice. We should be able to look at the incoming message, and sniff out anything starting with @
. If we find it, then we should...