From cd1d8b9b1ff55826426b1f8a235c744e67b47f53 Mon Sep 17 00:00:00 2001 From: Ginger Collison Date: Fri, 4 Oct 2019 14:23:39 -0500 Subject: [PATCH] Update random.md --- developing-with-nats/intro-1/random.md | 88 +++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/developing-with-nats/intro-1/random.md b/developing-with-nats/intro-1/random.md index 6d67ff1..10338b1 100644 --- a/developing-with-nats/intro-1/random.md +++ b/developing-with-nats/intro-1/random.md @@ -4,5 +4,91 @@ When a server goes down, there is a possible anti-pattern called the _Thundering However, if you want to disable the randomization process, so that servers are always checked in the same order, you can do that in most libraries with a connection options: -!INCLUDE "../../\_examples/reconnect\_no\_random.html" +{% tabs %} +{% tab title="Go" %} +```go +servers := []string{"nats://127.0.0.1:1222", + "nats://127.0.0.1:1223", + "nats://127.0.0.1:1224", +} + +nc, err := nats.Connect(strings.Join(servers, ","), nats.DontRandomize()) +if err != nil { + log.Fatal(err) +} +defer nc.Close() + +// Do something with the connection +``` +{% endtab %} + +{% tab title="Java" %} +```java +Options options = new Options.Builder(). + server("nats://demo.nats.io:4222"). + noRandomize(). // Disable reconnect shuffle + build(); +Connection nc = Nats.connect(options); + +// Do something with the connection + +nc.close(); +``` +{% endtab %} + +{% tab title="JavaScript" %} +```javascript +let nc = NATS.connect({ + noRandomize: false, + servers: ["nats://127.0.0.1:4443", + "nats://demo.nats.io:4222" + ] +}); +``` +{% endtab %} + +{% tab title="Python" %} +```python +nc = NATS() +await nc.connect( + servers=[ + "nats://demo.nats.io:1222", + "nats://demo.nats.io:1223", + "nats://demo.nats.io:1224" + ], + dont_randomize=True, + ) + +# Do something with the connection + +await nc.close() +``` +{% endtab %} + +{% tab title="Ruby" %} +```ruby +require 'nats/client' + +NATS.start(servers: ["nats://127.0.0.1:1222", "nats://127.0.0.1:1223", "nats://127.0.0.1:1224"], dont_randomize_servers: true) do |nc| + # Do something with the connection + + # Close the connection + nc.close +end +``` +{% endtab %} + +{% tab title="TypeScript" %} +```typescript +// will throw an exception if connection fails +let nc = await connect({ + noRandomize: false, + servers: ["nats://127.0.0.1:4443", + "nats://demo.nats.io:4222" + ] +}); +nc.close(); +``` +{% endtab %} +{% endtabs %}