ng2-STOMP-Over-WebSocket icon indicating copy to clipboard operation
ng2-STOMP-Over-WebSocket copied to clipboard

Reconnect handling

Open ib1987 opened this issue 8 years ago • 2 comments
trafficstars

Hi @devsullo,

this module is really useful, thanks for it. Please help me, how can i handle the reconnect situation? My client lifecycle:

  1. connect
  2. subscribe
  3. connection lost (e.g.: backend error)
  4. reconnect
  5. -> and at this point i need to subscribe again.

--Ben

ib1987 avatar Apr 13 '17 23:04 ib1987

Hi, Thank you @ib1987

I think one way to do it is to pass 'subscribe' to onConnect method and every time when connection is no longer available module will try to reconnect and when connection established every 'subscribe' what we passed will happened inside onConnect method

devsullo avatar Apr 14 '17 12:04 devsullo

I had the same problem. This was my old code, where after reconnection the subscriptions were lost:

stomp.startConnect().then(() => {
  stomp.done('init')
  stomp.subscribe( ... )
})

And this is the new working code: The subscriptions are renewed each time an onConnect event is received:

let originalOnConnect = stomp.onConnect
stomp.onConnect = (frame: any) => {
  originalOnConnect(frame)
  stomp.subscribe( ... )
}
stomp.startConnect().then(() => {
  stomp.done('init')
})`

Feature request: It would be great if the library could manage the subscriptions automatically :blush:

Xenoage avatar Jun 29 '17 15:06 Xenoage