Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for client to reconnect? #52

Closed
waylandc opened this issue Feb 19, 2019 · 3 comments
Closed

Example for client to reconnect? #52

waylandc opened this issue Feb 19, 2019 · 3 comments

Comments

@waylandc
Copy link

waylandc commented Feb 19, 2019

Would some kind soul please show me how to setup the Client to reconnect if the server closes connection? I'm guessing it has something to do with Client.disconnectdb but I have no idea how to use this.

Is this what the TestClientChanReconnect method is testing? I see the httptest.Server closing connections but how did the client reconnect?

@purehyperbole
Copy link
Member

In the case of a connection dropping, a Subscribe() will be retried with exponential backoff.

It will keep reconnecting until client.Unsubscribe() is called, which stops the client goroutine.

If you want to keep track of disconnects, you can use the callback like so:

client.OnDisconnect(func(c *sse.Client){
    log.Println("disconnected!")
})

@waylandc
Copy link
Author

In the case of a connection dropping, a Subscribe() will be retried with exponential backoff.

It will keep reconnecting until client.Unsubscribe() is called, which stops the client goroutine.

If you want to keep track of disconnects, you can use the callback like so:

client.OnDisconnect(func(c *sse.Client){
    log.Println("disconnected!")
})

Thanks for the explanation. Hope you don't mind me expanding my question but when it reconnects, isn't it supposed to only get messages after Last-Event-ID? Currently, it gets replayed all messages from the start.

@purehyperbole
Copy link
Member

You're right in that's how it should function, however if the stream you're reading from isn't sending any id values along with data messages, the Last-Event-ID will remain empty.

If you're able to please send some of the raw data from the stream, that would be super helpful.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants