Simple NATS client for the Crystal programming language.
- Add the dependency to your
shard.yml:
dependencies:
nats:
github: nats-io/nats.cr- Run
shards install
require "nats/client"
client = NATS::Client.new("nats://localhost:4222")
client.connect
client.subscribe("foo") do |msg|
puts "Received message on subject #{msg.subject}: #{msg.payload}"
end
client.publish("foo", "Hello, NATS!")
client.subscribe("bar") do |msg|
msg.reply "Received your message on bar: #{msg.payload}"
end
response = client.request("bar", "Hello, bar!")
puts "Received response: #{response.payload}"
client.request("bar") do |msg|
puts "Recieved async response: #{msg.payload}"
end
client.closeUnless otherwise noted, the NATS source files are distributed under the Apache Version 2.0 license found in the LICENSE file.