Example usage for org.springframework.messaging.simp.stomp StompHeaderAccessor setLogin

List of usage examples for org.springframework.messaging.simp.stomp StompHeaderAccessor setLogin

Introduction

In this page you can find the example usage for org.springframework.messaging.simp.stomp StompHeaderAccessor setLogin.

Prototype

public void setLogin(@Nullable String login) 

Source Link

Usage

From source file:org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler.java

/**
 * Open a "system" session for sending messages from parts of the application
 * not assoicated with a client STOMP session.
 *//*from ww  w .j a v  a  2  s  .c  om*/
private void openSystemSession() {

    RelaySession session = new RelaySession(STOMP_RELAY_SYSTEM_SESSION_ID) {
        @Override
        protected void sendMessageToClient(Message<?> message) {
            // ignore, only used to send messages
            // TODO: ERROR frame/reconnect
        }
    };
    this.relaySessions.put(STOMP_RELAY_SYSTEM_SESSION_ID, session);

    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.CONNECT);
    headers.setAcceptVersion("1.1,1.2");
    headers.setLogin(this.systemLogin);
    headers.setPasscode(this.systemPasscode);
    headers.setHeartbeat(0, 0); // TODO

    if (logger.isDebugEnabled()) {
        logger.debug("Sending STOMP CONNECT frame to initialize \"system\" TCP connection");
    }
    Message<?> message = MessageBuilder.withPayloadAndHeaders(new byte[0], headers).build();
    session.open(message);
}