Private Messaging with STOMP
Learn to implement direct, one-on-one private messaging between users using STOMP's user destinations.
Private Chat Essentials
Welcome! In this lesson, we'll learn how to build private messaging functionality into our chat application using WebSockets and STOMP.
Unlike public chat rooms where everyone receives messages, private messages (like direct messages or DMs) are sent specifically from one user to another. This requires a way to route messages directly to an individual's unique session.
STOMP User Destinations
STOMP provides a special destination prefix: /user. When a client subscribes to a destination like /user/queue/private-messages, the STOMP broker (and Spring) automatically translate this into a unique, session-specific queue for that particular authenticated user.
/userprefix: Indicates a user-specific destination.- Unique per user: Each user gets their own 'inbox' for private messages.
- Abstracted routing: You don't need to know the actual session ID.
All lessons in this course
- Designing a Chat Message Model
- Implementing Public Chat Rooms
- Private Messaging with STOMP
- Typing Indicators & Online Presence