连接时的弹簧靴Rabbitmq乒乓框架

时间:2018-10-17 18:43:45

标签: java spring-boot websocket rabbitmq stomp

我正在像我的STOMP WebSocket应用程序的消息代理一样使用Spring Boot和RabbitMQ。这是我的消息代理配置:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Value("${rabbitmq.host}")
    private String host;

    @Value("${rabbitmq.port}")
    private Integer port;

    @Value("${rabbitmq.login}")
    private String login;

    @Value("${rabbitmq.passcode}")
    private String passcode;

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/stomp")
                .setAllowedOrigins("*");
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableStompBrokerRelay("/topic")
            .setRelayHost(this.host)
            .setRelayPort(this.port)
            .setSystemLogin(this.login)
            .setSystemPasscode(this.passcode)
            .setSystemHeartbeatSendInterval(0)
            .setSystemHeartbeatReceiveInterval(0)
        ;
    }
}

在前端,我将stomp.js与下一个代码连接:

var socket = new WebSocket("ws://localhost:5000/stomp");
        stompClient = Stomp.over(socket);
        stompClient.heartbeat.outgoing = 0;
        stompClient.heartbeat.incoming = 0;
        stompClient.connect({}, function (data) {
            stompClient.subscribe('/topic', function (payload) {
            });
        }); 

在浏览器控制台中,我得到了下一个结果:

Opening Web Socket...
undefined
Web Socket Opened...

>>> CONNECT
accept-version:1.1,1.0
heart-beat:0,0

<<< PONG

<<< CONNECTED
server:RabbitMQ/3.6.6
heart-beat:0,0
version:1.1

connected to server RabbitMQ/3.6.6

>>> SUBSCRIBE
id:sub-0
destination:/topic

谁能解释为什么我在CONNECT帧之后从服务器“ \ n”(PONG帧)收到了消息?因为在我的代理配置中,我已关闭心跳:

.setSystemHeartbeatSendInterval(0)
.setSystemHeartbeatReceiveInterval(0)

当然,我已经在我的js脚本中关闭了用于连接标头的心跳:

stompClient.heartbeat.outgoing = 0;
stompClient.heartbeat.incoming = 0;

非常感谢您的帮助

0 个答案:

没有答案