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

Simpler connect #156

Merged
merged 2 commits into from
Aug 29, 2018
Merged

Simpler connect #156

merged 2 commits into from
Aug 29, 2018

Conversation

wallyqs
Copy link
Member

@wallyqs wallyqs commented Aug 29, 2018

Adds support for connecting to NATS, following similar usage as in the latest Go client and still backwards compatible with options based connect API.

    # Only specifying endpoint uses NATS default scheme and port.
    NATS.connect("demo.nats.io") do |nc|
      # ...
    end

    # Setting custom server URI to connect.
    NATS.connect("nats://localhost:4222") do |nc|
    end

    # Setting username and password to authenticate.
    NATS.connect("nats://user:password@localhost:4222") do |nc|
      # ...
    end

    # Specifying explicit list of servers via options.
    NATS.connect(servers: ["nats://127.0.0.1:4222","nats://127.0.0.1:4223","nats://127.0.0.1:4224"]) do |nc|
      # ...
    end

    # Using comma separated array to define list of servers.
    NATS.connect("nats://localhost:4223,nats://localhost:4224") do |nc|
       # ...
    end

    # Setting infinite reconnect retries with 2 seconds back off against custom URI.
    NATS.connect("demo.nats.io:4222", max_reconnect_attempts: -1, reconnect_time_wait: 2) do |nc|
      # ...
    end

Makes it possible to only set a single string with
for connecting to a NATS cluster.

  NATS.connect("nats://127.0.0.1:4222")

  NATS.connect("nats://127.0.0.1:4222,nats://127.0.0.1:4223")

If scheme and port are not defined, then assume NATS defaults:

  NATS.connect("demo.nats.io")

  NATS.connect("demo.nats.io", max_reconnect_attempts: -1)

Backwards compatible with original API so could
still use a Hash with options:

  NATS.connect(uri: "nats://demo.nats.io:4222")

  NATS.connect(servers: ["nats://demo.nats.io:4222"])

Signed-off-by: Waldemar Quevedo <wally@synadia.com>
@wallyqs wallyqs changed the base branch from no-echo to master August 29, 2018 05:25
@wallyqs wallyqs merged commit 64c63da into master Aug 29, 2018
@wallyqs wallyqs deleted the simpler-connect branch August 29, 2018 17:41
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

Successfully merging this pull request may close these issues.

None yet

1 participant