我有以下课程:
@Autowired
private WebSocketStompClient client;
private volatile StompSession stompSession;
public ListenableFuture<StompSession> connect(String token) {
.....
//connecting
return client.connect(settingsBean.getMarketPlaceUrl(),
new WebSocketHttpHeaders(headers),
stompHeadersConnect,
new StompSessionHandlerAdapter() {
@Override
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
stompSession = session;
...
session.subscribe(stompHeadersSubscribe, myFrameHandler);
// As I understand I don't have guarantees that subscription was completed successfully
}
}
public void send(String url, Object obj) {
stompSession.send(url, obj);
}
有时send方法在建立连接时调用,但是订阅 - 尚未确定。
如何等待订阅成立的时刻?