nats-io/nats.net.v2

Possibility to specifiy multiple servers / urls

heckradr opened this issue ยท 3 comments

Proposed change

I'm upgrading an old .net framework application to .net 8. At this point I'm also updating from nats.client to nats.net.

I miss the option to specify multiple servers/URLs when connecting.

In the previous nats.client I can pass multiple servers to the NATS.Client.Options (it was a string[]). The new nats.net client has only a string to specify the server url. I tried to concat multiple servers comma separated but this does not work.

Is this still possible and I just missed it?

Use case

I need to specify multiple hostnames / ip addresses when connecting to a nats-cluster.

Contribution

No response

mtmk commented

I tried to concat multiple servers comma separated but this does not work.

That should work e.g.:

await using var nats = new NatsConnection(new NatsOpts
{
    Url = "nats://localhost:4222,1.2.3.4,192.168.0.1:1234,tls://nats1.example.com,wss://nats2.example.com:443",
});
mtmk commented

I'm upgrading an old .net framework application to .net 8. At this point I'm also updating from nats.client to nats.net.

that's great ๐ŸŽ‰

please feel free to reach out here on GH or on slack.nats.io / #dotnet. we have a fairly active community and growing.

That should work e.g.:

await using var nats = new NatsConnection(new NatsOpts
{
    Url = "nats://localhost:4222,1.2.3.4,192.168.0.1:1234,tls://nats1.example.com,wss://nats2.example.com:443",
});

Oh, shame on me - I had whitespaces in my concatted url, so I got a Exception. Now it's working. Thank you very much for the fast feedback :-)