Nats Async
nats-async packages the nats-test prototype as a Ruby gem that uses gem async.
Installation
Add the gem to your bundle:
gem "nats-async"Or install it directly:
gem install nats-asyncUsage
require "nats-async"
connector = NatsAsync::SimpleConnector.new(url: "nats://127.0.0.1:4222", verbose: false)
connector.run(duration: 1) do |client, task|
client.subscribe("demo.subject") do |message|
puts "received: #{message.data}"
task.stop
end
client.publish("demo.subject", "hello")
endExamples
Core pub/sub:
bundle exec ruby examples/basic_pub_sub.rbJetStream publish and pull:
bundle exec ruby examples/jetstream_roundtrip.rbThe integration spec boots the bundled bin/nats-server and runs these examples locally.
Development
bundle install
bundle exec rspec
rake build