Search code examples
springspring-mvcspring-websocket

Spring 4.2.0 - How to use SimpUserRegistry


According with the Spring 4.2.0 documentation, item 5.5, I'm trying to use SimpUserRegistry to get the users list connected to an websockets/STOMP endpoint ...but I'm pretty new on Spring and I just don't know where/how to use this class. Can you provide me an example or point me in the right direction?


Solution

  • Just inject SimpUserRegistry as a dependency. Here's an example on printing the username of all connected users:

    @Autowired private SimpUserRegistry userRegistry;
    
    public void printConnectedUsers() { 
        userRegistry.getUsers().stream()
                        .map(u -> u.getName())
                        .forEach(System.out::println);
    }