Class: Polyn::Nats

Inherits:
Object
  • Object
show all
Defined in:
lib/polyn/nats.rb,
lib/polyn/nats/msg.rb

Overview

Adapter/wrapper around Nats

Defined Under Namespace

Classes: Msg

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nats) ⇒ Nats

Returns a new instance of Nats.



7
8
9
# File 'lib/polyn/nats.rb', line 7

def initialize(nats)
  @nats = nats
end

Instance Attribute Details

#natsObject (readonly)

Returns the value of attribute nats.



11
12
13
# File 'lib/polyn/nats.rb', line 11

def nats
  @nats
end

Instance Method Details

#jetstreamObject



21
22
23
# File 'lib/polyn/nats.rb', line 21

def jetstream
  @jetstream ||= @nats.jetstream
end

#publish(type, json, reply, **opts) ⇒ Object



13
14
15
# File 'lib/polyn/nats.rb', line 13

def publish(type, json, reply, **opts)
  @nats.publish(type, json, reply, **opts)
end

#subscribe(type, opts = {}, &callback) ⇒ Object



17
18
19
# File 'lib/polyn/nats.rb', line 17

def subscribe(type, opts = {}, &callback)
  @nats.subscribe(type, opts) { |msg| callback.call(Polyn::Nats::Msg.new(msg)) }
end