Example usage for org.springframework.messaging.simp.user UserDestinationResult getTargetDestinations

List of usage examples for org.springframework.messaging.simp.user UserDestinationResult getTargetDestinations

Introduction

In this page you can find the example usage for org.springframework.messaging.simp.user UserDestinationResult getTargetDestinations.

Prototype

public Set<String> getTargetDestinations() 

Source Link

Document

The target destinations that the source destination was translated to, one per active user session, e.g.

Usage

From source file:org.springframework.messaging.simp.user.UserDestinationMessageHandler.java

@Override
public void handleMessage(Message<?> message) throws MessagingException {
    Message<?> messageToUse = message;
    if (this.broadcastHandler != null) {
        messageToUse = this.broadcastHandler.preHandle(message);
        if (messageToUse == null) {
            return;
        }/*w  ww  .  j a v a 2  s .  c o  m*/
    }

    UserDestinationResult result = this.destinationResolver.resolveDestination(messageToUse);
    if (result == null) {
        return;
    }

    if (result.getTargetDestinations().isEmpty()) {
        if (logger.isTraceEnabled()) {
            logger.trace("No active sessions for user destination: " + result.getSourceDestination());
        }
        if (this.broadcastHandler != null) {
            this.broadcastHandler.handleUnresolved(messageToUse);
        }
        return;
    }

    SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.wrap(messageToUse);
    initHeaders(accessor);
    accessor.setNativeHeader(SimpMessageHeaderAccessor.ORIGINAL_DESTINATION, result.getSubscribeDestination());
    accessor.setLeaveMutable(true);

    messageToUse = MessageBuilder.createMessage(messageToUse.getPayload(), accessor.getMessageHeaders());
    if (logger.isTraceEnabled()) {
        logger.trace("Translated " + result.getSourceDestination() + " -> " + result.getTargetDestinations());
    }
    for (String target : result.getTargetDestinations()) {
        this.messagingTemplate.send(target, messageToUse);
    }
}