stompjs icon indicating copy to clipboard operation
stompjs copied to clipboard

How to get inmediate feedback after subscription

Open aalbericio opened this issue 2 years ago • 1 comments

Hello,

When I execute this piece of code:

const susbcription = this.client.subscribe(...)

It always returns a valid subscription, even if the final destination does not exist on the server.

It is also true that I automatically receive a Stomp Error but I'd also like to get that "feedback" at subscription time. Is it possible?

I would like to do somethig like:

const subscription = this.client.subscribe(...)

if (subscription) {
...
} else {
...
}

Thanks in advance.

aalbericio avatar Mar 27 '23 10:03 aalbericio

The STOMP protocol does not offer a mechanism to check whether an endpoint exists or whether the client has the required permissions. Please check https://stomp.github.io/stomp-specification-1.2.html

The best I can recommend is to use receipts https://stomp-js.github.io/api-docs/latest/classes/Client.html#watchForReceipt. However, if the subscription fails, you will still get an error frame followed by a disconnect. In addition, the actual behaviour may vary based on the specific broker.

kum-deepak avatar Mar 27 '23 11:03 kum-deepak