class BPS::Subscriber::STAN
Public Class Methods
new(cluster_id, client_id, **opts)
click to toggle source
@param [String] cluster ID. @param [String] client ID. @param [Hash] options.
Calls superclass method
# File lib/bps/subscriber/stan.rb, line 10 def initialize(cluster_id, client_id, **opts) super() @client = ::BPS::STAN.connect(cluster_id, client_id, **opts) end
Public Instance Methods
close()
click to toggle source
Close the subscriber.
# File lib/bps/subscriber/stan.rb, line 28 def close # NATS/STAN does not survive multi-closes, so close only once: @client&.close @client = nil end
subscribe(topic, **opts) { |data| ... }
click to toggle source
Subscribe to a topic @param topic [String] topic the topic name.
# File lib/bps/subscriber/stan.rb, line 18 def subscribe(topic, **opts) # important opts: # - queue: 'queue-name' # https://docs.nats.io/developing-with-nats-streaming/queues # - durable_name: 'durable-name' # https://docs.nats.io/developing-with-nats-streaming/durables @client.subscribe(topic, **opts) do |msg| yield msg.data # TODO: maybe yielding just bytes is not too flexible? But IMO can wait till (much) later end end