class

Alumna::Nats

Inherits Reference < Object

One NATS client for the process. Not a Service adapter.

Constructors

new(servers : URI | String | Array(URI) | Array(String), *, nkeys_file : String | Nil = nil, user_credentials : String | Nil = nil) : self | Error

Open a client. servers is a URI, a URL string, or a list of servers. Pass nkeys_file or user_credentials when the server requires them. Returns Error when the driver fails. Raises ArgumentError for a bad URL.

Source

Class methods

from_env(name : String = "NATS_URL", *, nkeys_file : String | Nil = nil, user_credentials : String | Nil = nil) : self | Error
Source
from_uri(uri : URI | String, *, nkeys_file : String | Nil = nil, user_credentials : String | Nil = nil) : self | Error
Source

Instance methods

client
Source
close
Source
flush

Push the output buffer and wait for a PONG.

Source
jetstream

JetStream helper. You must create a stream and a durable push consumer. Publish does not create a stream. Subscribe does not create a consumer. The handler does not ack. For a job queue, create the stream with retention: :workqueue.

Source
ping

Wait for a PONG. Uses flush.

Source
publish(subject : String, payload : String | Bytes) : Nil | Error

Core publish. Does not wait for subscribers. Payload is String or Bytes. Empty or invalid subject raises ArgumentError. App owns the subject name.

Source
subscribe(subject : String, *, queue_group : String | Nil = nil, &block : Message -> ) : Subscription | Error

Core subscribe. Does not block. With no queue_group, each current subscriber gets a copy (fan-out). With queue_group, subscribers in that group compete (one delivery per message). Empty or invalid subject, or empty queue_group, raises ArgumentError. Wildcards * and > are valid here. Core NATS does not persist the message.

Source
unsubscribe(subscription : Subscription) : Nil | Error
Source

Nested types