Comments (4)
此时,说明连接已经断开,而 onDisconnected
回调 已经 或 正在 或 即将 在另外一个线程里 被执行
from okhttps.
配置心跳后,关闭服务端,没有触发任何回调。
服务端配置:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
public static final String END_POINT = "stomp-kafka";
public static final String BROKER_PREFIX = "/kafka";
private static final long HEAR_BEAT_MILLS = 5000L;
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint(END_POINT).setAllowedOrigins("*").withSockJS();
registry.addEndpoint("ok-https");
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
final ThreadPoolTaskScheduler heartBeatPool = new ThreadPoolTaskScheduler();
heartBeatPool.setPoolSize(1);
heartBeatPool.setThreadNamePrefix("stomp-heart-beat-");
heartBeatPool.initialize();
registry.enableSimpleBroker(BROKER_PREFIX)
.setHeartbeatValue(new long[]{HEAR_BEAT_MILLS, HEAR_BEAT_MILLS})
.setTaskScheduler(heartBeatPool)
;
registry.setApplicationDestinationPrefixes("/server");
}
客户端配置:
@Bean
public Stomp okHttps(StompConfigEntity stompConfigEntity) {
final Stomp stomp = Stomp.over(OkHttps.webSocket(stompConfigEntity.getUrl()).heatbeat(5, 5));
stomp.setOnConnected(data -> {
log.info("Stomp Connected {}", data);
subscribe(stompConfigEntity.getTopics(), data);
})
.setOnDisconnected(data -> {
log.info("Stomp Disconnected {}", data);
didSubscribe = false;
stomp.connect();
})
.setOnError(data -> log.info("Error : {}", data))
.setOnException(data -> {
log.warn("Exception!", data);
didSubscribe = false;
stomp.connect();
});
stomp.connect();
return stomp;
}
private void subscribe(List<String> topics, Stomp stomp) {
if (this.didSubscribe) {
return;
}
this.didSubscribe = true;
for (String topic : topics) {
stomp.subscribe(topic, null, message -> log.info("Subscribe Handler : {}", message.getPayload()));
}
}
请问服务端和客户端这样的心跳配置正确吗?
from okhttps.
OnConnected
回调有执行吗?如果没有,说明根本没有连上这个服务器,可以尝试把 withSockJS
去掉试试
from okhttps.
OnConnected
回调有执行吗?如果没有,说明根本没有连上这个服务器,可以尝试把withSockJS
去掉试试
回调执行了 我开放了两个endpoint 一个是withJs的 另一个是没有
from okhttps.
Related Issues (20)
- stomp连接时发生服务端异常,重连过程中异常,导致stomp状态异常 HOT 1
- 希望支持链式嵌套json数组解析为List<T> HOT 4
- java.lang.NoSuchFieldError: Companion HOT 2
- 有点难用 HOT 1
- 我还是用我自己封装的吧 HOT 1
- 请问get请求怎样添加参数 HOT 2
- 存在流未关闭 HOT 1
- 库打包后编译出错:Failed to transform ‘okhttps-3.5.2.jar' using Jetifier HOT 1
- 抱歉是看错。 挺好用的库
- 网络连接超时,就出现 OkHttpsException 异步请求异常 HOT 2
- 建议更新版本 HOT 3
- Kotlin 协程支持 HOT 3
- 建议增加fastjson2的支持 HOT 2
- mapper.toBean()怎么指定使用Jackson来进行反序列化? HOT 5
- Consumer导致在Android 24以下无法使用 HOT 2
- 新建多个HTTP实例问题 HOT 1
- 报错timeout 链接没有释放 HOT 1
- websocket服务支持stomp么 HOT 1
- OkHttpsConfig全局配置的responseListener和completeListener只对OkHttps.async异步方法有效,OkHttps.sync方法不走全局回调 HOT 1
- Consider support jsoniter?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from okhttps.