I have the following class:
@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);
}
Sometimes send method invokes when connect has already been established, but subscribtion - was not yet.
How to await moment when subscription have been established?