Class: BPS::Publisher::STAN

Inherits:
Abstract
  • Object
show all
Defined in:
lib/bps/publisher/stan.rb

Defined Under Namespace

Classes: Topic

Instance Method Summary collapse

Constructor Details

#initialize(cluster_id, client_id, **opts) ⇒ STAN

Returns a new instance of STAN.

Parameters:

  • cluster (String)

    ID.

  • client (String)

    ID.

  • options. (Hash)


27
28
29
30
31
32
# File 'lib/bps/publisher/stan.rb', line 27

def initialize(cluster_id, client_id, **opts)
  super()

  @topics = {}
  @client = ::BPS::STAN.connect(cluster_id, client_id, **opts)
end

Instance Method Details

#closeObject



38
39
40
41
42
43
44
# File 'lib/bps/publisher/stan.rb', line 38

def close
  super

  # NATS/STAN does not survive multi-closes, so close only once:
  @client&.close
  @client = nil
end

#topic(name) ⇒ Object



34
35
36
# File 'lib/bps/publisher/stan.rb', line 34

def topic(name)
  @topics[name] ||= self.class::Topic.new(@client, name)
end