Ruby client for NATS, the cloud native messaging system.
Release with support for NATS v2 auth features
require 'nats/client'
NATS.start("tls://connect.ngs.global", user_credentials: "/path/to/creds") do |nc|
nc.subscribe("hello") do |msg|
puts "[Received] #{msg}"
end
nc.publish('hello', 'world')
end
require 'nats/client'
NATS.start("tls://connect.ngs.global", nkeys_seed: "path/to/seed.txt") do |nc|
nc.subscribe("hello") do |msg|
puts "[Received] #{msg}"
end
nc.publish('hello', 'world')
end
--creds
option to nats-pub
, nats-sub
, nats-queue
toolsFixed being able to use 'tls' as the scheme when connecting with a single URL
NATS.connect("tls://demo.nats.io:4443")
Support for drain mode
(https://github.com/nats-io/ruby-nats/pull/157)
This feature allows clients to gracefully disconect, letting the subscribers handle any inflight messages that may have been sent by the server already.
NATS.start(drain_timeout: 1) do |nc|
NATS.subscribe('foo', queue: "workers") do |msg, reply, sub|
nc.publish(reply, "ACK:#{msg}")
end
NATS.subscribe('bar', queue: "workers") do |msg, reply, sub|
nc.publish(reply, "ACK:#{msg}")
end
NATS.subscribe('quux', queue: "workers") do |msg, reply, sub|
nc.publish(reply, "ACK:#{msg}")
end
EM.add_timer(2) do
next if NATS.draining?
# Drain gracefully closes the connection.
NATS.drain do
puts "Done draining. Connection is closed."
end
end
end
Support for no_echo
mode (https://github.com/nats-io/ruby-nats/pull/155)
When connected to a NATS Server v1.2.0 or above, a client can now opt to avoid receiving messages that it itself has published.
NATS.connect(no_echo: true)
NATS.connect
API is now more similar to how it works in the Go client (https://github.com/nats-io/ruby-nats/pull/156):
# Assume 'nats://' scheme
NATS.connect("demo.nats.io:4222")
# Complete with scheme a la Go client classic usage.
NATS.connect("nats://demo.nats.io:4222")
# Use default 4222 port.
NATS.connect("demo.nats.io")
# Explicit cluster list still supported
NATS.connect(servers: ["nats://demo.nats.io:4222"])
Client now supports token based authorization
NATS.connect(token: "deadbeef")
NATS.connect(uri: "nats://[email protected]:4222")
NATS.connect("nats://[email protected]:4222")
Minor version release including fixes to support multiple CAs when using secure connections.
TLS Peer verification: ssl_verify_peer
does not support multiple CAs
https://github.com/nats-io/ruby-nats/issues/151 Thanks to @h4xnoodle @pivotal-jamil-shamy for the contribution.
name
as part of CONNECT options (https://github.com/nats-io/ruby-nats/pull/145)require
(https://github.com/nats-io/ruby-nats/pull/144)Minor release which changes nats client dependencies so that only Eventmachine > 1.2 is required