gpt4 book ai didi

stomp - Spring STOMP over WebSockets 不调度心跳

转载 作者:行者123 更新时间:2023-12-04 02:49:35 26 4
gpt4 key购买 nike

我们有一个 Spring over WebSockets 连接,我们正在传递一个 CONNECT框架:

CONNECT\naccept-version:1.2\nheart-beat:10000,10000\n\n\u0000

处理程序确认,开始一个新 session ,然后返回:
CONNECTED
version:1.2
heart-beat:0,0

但是,我们想要心跳,以便我们可以保持 WebSocket 打开。我们没有使用 SockJS。

我逐步完成了 Spring 消息处理程序:
StompHeaderAccessor [headers={simpMessageType=CONNECT, stompCommand=CONNECT, nativeHeaders={accept-version=[1.2], heart-beat=[5000,0]}, simpSessionAttributes={}, simpHeartbeat=[J@5eba717, simpSessionId=46e855c9}]

得到 heart-beat后(native header),它设置看起来像内存地址 simpHeartbeat=[J@5eba717, simpSessionId=46e855c9}]
值得注意的是,在代理验证之后:
Processing CONNECT session=46e855c9 (这里的 sessionId 与 simpSessionId 不同)?

更早运行时 TRACE调试 我看到一条通知“调度心跳......”或类似的东西......虽然我现在没有看到它?

知道发生了什么吗?

谢谢

我在 documentation 中找到了解释:

SockJS Task Scheduler stats from thread pool of the SockJS task scheduler which is used to send heartbeats. Note that when heartbeats are negotiated on the STOMP level the SockJS heartbeats are disabled.



SockJS 心跳与 STOMP 心跳不同吗?

最佳答案

从 Spring 4.2 开始,您可以使用 Stomp over SockJS 和内置 SimpleBroker 从服务器端完全控制心跳协商结果:

public class WebSocketConfigurer extends AbstractWebSocketMessageBrokerConfigurer {

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
ThreadPoolTaskScheduler te = new ThreadPoolTaskScheduler();
te.setPoolSize(1);
te.setThreadNamePrefix("wss-heartbeat-thread-");
te.initialize();

config.enableSimpleBroker("/")
/**
* Configure the value for the heartbeat settings. The first number
* represents how often the server will write or send a heartbeat.
* The second is how often the client should write. 0 means no heartbeats.
* <p>By default this is set to "0, 0" unless the {@link #setTaskScheduler
* taskScheduler} in which case the default becomes "10000,10000"
* (in milliseconds).
* @since 4.2
*/
.setHeartbeatValue(new long[]{heartbeatServer, heartbeatClient})
.setTaskScheduler(te);
}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint(.....)
.setAllowedOrigins(....)
.withSockJS();
}
}

关于stomp - Spring STOMP over WebSockets 不调度心跳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39220647/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com