-
Notifications
You must be signed in to change notification settings - Fork 151
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
Add RetryOnFailedConnect #443
Comments
So, is this feature coming to the library? Are there commits adding this? |
There is a feature in progress that will allow you to retry on the initial connect. Currently any failure on initial connect does not try to retry. There should be a PR any day now and a pre-release by start of next week. |
That will be great! I'm building a mobile app that I want to remain connected as much as possible to react to events in real-time. Since the initial connection behaves differently than auto-reconnection, it's a bit awkward for me and I have to do something like this: using NATS.Client;
public class MyNatsConnectionWrapper : IDisposable
{
public bool Connected => Connection?.State == ConnState.CONNECTED;
public IConnection? Connection { get; private set; }
public MyNatsConnectionWrapper(Options options, CancellationToken cancelToken)
{
Task.Run(async () =>
{
while (!cancelToken.IsCancellationRequested)
{
try
{
Connection = new ConnectionFactory().CreateConnection(options);
}
catch (NATSConnectionException ex)
{
//LogThat(ex);
}
await Task.Delay(3333, cancelToken).SuppressCanceledException(cancelToken);
}
}, cancelToken);
}
public void Dispose() => Connection?.Dispose();
} |
Yeah, it will be changed to this, adding a bool flag to the signature (bool reconnectOnConnect = true) to the create connection, true means reconnect on connect.
|
@scottf I couldn't get this to work at all (package version 1.1.1) My connection just sits in a |
@ronnieoverby Please get me some details and I will try to reproduce this. Do you know what kind of error or what is happening where the connection is broken? |
@scottf Here you are, sir: There aren't errors. It just never seems to connect. I left some comments in the repro program. |
@ronnieoverby Fixed here: https://github.com/nats-io/nats.net/pull/854 I will have a pre-release available in about an hour. 1.1.2-pre3 |
It took me a lot longer than expected to get a review. I'm just publishing it now. |
Currently, initial connect behavior attempts the server list and then gives up. Traverse the connection list and retry honoring reconnect attempt values.
See: nats-io/nats.go#581
Option to mirror go:
Options.RetryOnFailedConnect = true;
The text was updated successfully, but these errors were encountered: