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

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

Introduction

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

Prototype

public String getSubscribeDestination() 

Source Link

Document

The user destination in the form expected when a client subscribes, 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;
        }// ww  w .j  a va2 s .com
    }

    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);
    }
}