Releases: nats-io/nats-pure.rb
Releases · nats-io/nats-pure.rb
Release v2.4.0
Fixed
- Fixed loading Rails Engine by @palkan in (#132)
- Fixed crash when assigning URI port to default value by @cavalle in (#135)
Added
- Add support for consumer multiple filters and streams/consumers metadata (#138)
# Creating a stream with multiple subjects
js.add_stream(name: "MULTI_FILTER", subjects: ["foo.one.*", "foo.two.*", "foo.three.*"])
# PullSubscriber that takes an array and creates a consumer with multiple filters .
js.pull_subscribe(["foo.one.1", "foo.two.2"], "example")
# PushSubscriber that takes an array and creates a consumer with multiple filters .
js.subscribe(["foo.one.1", "foo.three.3"])
# via JetStream#add_consumer API
consumer = js.add_consumer("MULTI_FILTER", {
name: "my-consumer",
filter_subjects: ["foo.one.*", "foo.two.*"]
})
# Pass nil to both subject and durable consumer name to bind to already created consumer
js.pull_subscribe(nil, nil, name: "my-consumer", stream: "MULTI_FILTER")
# Stream with metadata
stream = js.add_stream({
:name => "WITH_METADATA",
:metadata => {
'foo': 'bar',
'hello': 'world'
}
})
Full Changelog: v2.3.0...v2.4.0
Release v2.3.0
What's Changed
- Update gemspec to automatically include .rb and .rbs files by @zaben903 in #95
- Fork detection and automatic reconnect in child process by @Envek in #114
- Reset stats and server_pool after_fork by @wallyqs in #118
- Delayed connection: allow to initialize client without connecting by @Envek in #116
- Handling subscription messages in a thread pool by @Envek in #117
- Show ellipsis when truncating data in message by @capps in #112
- Integrate with Rails Executor for subscription callbacks resource cleanup by @Envek in #120
- Include LICENSE and README into built gem package by @Envek in #126
- WebSocket feature by @Envek in #127
- Support connecting to NATS cluster over WebSocket by @Envek in #121
- Fix lazy connection after code reload in Rails by @Envek in #124
New Contributors
- @Envek made their first contribution in #115
- @capps made their first contribution in #112
- @bruth made their first contribution in #130
Full Changelog: v2.2.1...v2.3.0
Release v2.2.1
What's Changed
- Added RBS definitions by @zaben903 in #82
- Added ability to edit an existing stream by @zaben903 in #83
- Split js.rb into smaller files to ease debugging and readability by @zaben903 in #80
- Fixed clustered example by @rodrigc in #90
- Fixed headers parser error when there were inline status and headers
- Fixed issue with activesupport ignoring
to_json
implementation - Changed README example to clarify pull subscribe usage
Full Changelog: v2.2.0...v2.2.1
Release v2.2.0
Added
- Added client updates for NATS v2.9.0
- Added support for KeyValue direct mode and republish
- Added support to create consumers using
name
Full Changelog: v2.1.2...v2.2.0
Release v2.1.2
Fixed
- Fixed being able to configure JetStream push consumers when created with susbcribe
js.subscribe("custom", durable: 'example', config: { deliver_policy: 'new' })
Added
- Updated JetStream StreamConfig and UpdatedConfig types to have more parity with latest version of the server
Release v2.1.0
Added
- Added
ignore_discovered_urls
to ignore INFO advertisements from server (#73)
NATS.connect(servers: ['nats://127.0.0.1:4444'], ignore_discovered_urls: true)
Fixed
Release v2.0.0
Revamped version of the with more similar APIs to the Go client, and initial support for JetStream.
To install add the following to your Gemfile:
gem 'nats-pure', '2.0.0'
require 'nats'
# Connect to server that has JetStream support, e.g.
#
# nats-server -js
#
nc = NATS.connect("localhost")
# Create JetStream context.
js = nc.jetstream
# Create Stream that will persist messages from foo subject.
begin
info = js.add_stream(name: "sample-stream", subjects: ["foo"])
rescue => e
puts "Error: #{e}"
end
# Send 10 messages and wait to get an ack that they have been persisted.
10.times do |i|
ack = js.publish("foo", "hello world: #{i}", timeout: 2)
puts "Published: #{ack.seq}"
end
# Create pull based consumer.
psub = js.pull_subscribe("foo", "psub")
# Fetch 3 messages from consumer.
msgs = psub.fetch(3)
msgs.each do |msg|
puts " ACK: Stream Seq: #{msg.metadata.sequence.stream} || Consumer Seq: #{msg.metadata.sequence.consumer}"
msg.ack
end
# Get latest consumer info.
cinfo = psub.consumer_info
puts "Consumer '#{cinfo.name}' Pending Messages: #{cinfo.num_pending}"
# Subscribe is now dispatched a NATS::Msg that may include headers
nc.subscribe("hello") do |msg|
puts "Received on '#{msg.subject}': Data: #{msg.data} || Header: #{msg.header}"
msg.respond("OK") if msg.reply
end
sub = nc.subscribe("hello")
# Can use publish to send a message with headers.
nc.publish("hello", header: { 'quux': 'quuz'})
nc.publish_msg(NATS::Msg.new(subject: "hello", data: "world", header:{ 'foo': 'bar'}))
# Request also supports publishing with headers.
msg = nc.request("hello", header: { 'a': 'b'})
puts "Response #{msg.data}"
msg = nc.request_msg(NATS::Msg.new(subject: "hello", data: "world!!!", header:{ 'foo': 'bar'}))
puts "Response #{msg.data}"
# Can also use iterator style to consume messages now.
msg = sub.next_msg
puts "Received on '#{msg.subject}': Data: #{msg.data} || Header: #{msg.header}"
msg = sub.next_msg(timeout: 2)
puts "Received on '#{msg.subject}': Data: #{msg.data} || Header: #{msg.header}"
begin
sub.next_msg(timeout: 1)
rescue NATS::Timeout => e
# puts "Timeout since no new messages yet: #{e}"
end
nc.flush
nc.close
Release v2.0.0 (pre-alpha)
Revamped version of the with more similar APIs to the Go client, and initial support for JetStream.
To install add the following to your Gemfile:
gem 'nats-pure', '2.0.0.pre.alpha'
require 'nats'
# Connect to server that has JetStream support, e.g.
#
# nats-server -js
#
nc = NATS.connect("localhost")
# Create JetStream context.
js = nc.jetstream
# Create Stream that will persist messages from foo subject.
begin
info = js.add_stream(name: "sample-stream", subjects: ["foo"])
rescue => e
puts "Error: #{e}"
end
# Send 10 messages and wait to get an ack that they have been persisted.
10.times do |i|
ack = js.publish("foo", "hello world: #{i}", timeout: 2)
puts "Published: #{ack.seq}"
end
# Create pull based consumer.
psub = js.pull_subscribe("foo", "psub")
# Fetch 3 messages from consumer.
msgs = psub.fetch(3)
msgs.each do |msg|
puts " ACK: Stream Seq: #{msg.metadata.sequence.stream} || Consumer Seq: #{msg.metadata.sequence.consumer}"
msg.ack
end
# Get latest consumer info.
cinfo = psub.consumer_info
puts "Consumer '#{cinfo.name}' Pending Messages: #{cinfo.num_pending}"
# Subscribe is now dispatched a NATS::Msg that may include headers
nc.subscribe("hello") do |msg|
puts "Received on '#{msg.subject}': Data: #{msg.data} || Header: #{msg.header}"
msg.respond("OK") if msg.reply
end
sub = nc.subscribe("hello")
# Can use publish to send a message with headers.
nc.publish("hello", header: { 'quux': 'quuz'})
nc.publish_msg(NATS::Msg.new(subject: "hello", data: "world", header:{ 'foo': 'bar'}))
# Request also supports publishing with headers.
msg = nc.request("hello", header: { 'a': 'b'})
puts "Response #{msg.data}"
msg = nc.request_msg(NATS::Msg.new(subject: "hello", data: "world!!!", header:{ 'foo': 'bar'}))
puts "Response #{msg.data}"
# Can also use iterator style to consume messages now.
msg = sub.next_msg
puts "Received on '#{msg.subject}': Data: #{msg.data} || Header: #{msg.header}"
msg = sub.next_msg(timeout: 2)
puts "Received on '#{msg.subject}': Data: #{msg.data} || Header: #{msg.header}"
begin
sub.next_msg(timeout: 1)
rescue NATS::Timeout => e
# puts "Timeout since no new messages yet: #{e}"
end
nc.flush
nc.close
Release v0.7.2
Added
- Added
NATS.connect
module method that returns aNATS::IO::Client
# Returns a new NATS::IO::Client.new instance
nc = NATS.connect("nats://demo.nats.io:4222")
nc = NATS.connect(servers: ["nats://demo.nats.io:4222"])
- Added logic to prevent multiple uses of
connect
when using the same client instance across different threads.
nc = NATS::IO::Client.new
nc.connect("nats://demo.nats.io:4222")
nc.connect("nats://demo.nats.io:4222") # Will not reattempt to connect if already called once.
Fixed
- Fixed
old_request
handling of NATS +v2.2 servers when there are no responders
Release v0.7.0
This implements support for headers that got introduced in NATS v2.2.
Added
- Added
publish_msg
andrequest_msg
that can be used to dispatch aNATS::Msg
type
msg = NATS::Msg.new(subject: 'hello', data: data, header: {'foo': 'bar'})
resp = nc.request_msg(msg, timeout: 1)
Currently to receive headers a callback requires the correct following arity:
nc.subscribe("hello") do |data, reply, subject, header|
puts header
end
- Added support for no responders.
In case of making a request with no responders then a NATS::IO::NoRespondersError
is now yield by default.
No responders feature can be disabled by using no_responders: false
option on connect
nc = NATS::IO::Client.new
nc.connect(servers: [@s.uri], no_responders: false)
- Added
old_style
option for when making a request, for example:
pull_req = { no_wait: true, batch: 1}
resp = nc.request("$JS.API.CONSUMER.MSG.NEXT.foojs.sample", pull_req.to_json, old_style: true)
Fixed
- Fixed leak of futures when a request times out #47