Method: Polyn::PullSubscriber#initialize

Defined in:
lib/polyn/pull_subscriber.rb

#initialize(fields) ⇒ PullSubscriber

is more than the ‘source_root`

Parameters:

  • fields (Object)

    :nats - Connected NATS instance from ‘NATS.connect`

  • fields (String)

    :type - The type of event

Options Hash (fields):

  • :source (String)
    • If the ‘source` portion of the consumer name



12
13
14
15
16
17
18
19
20
# File 'lib/polyn/pull_subscriber.rb', line 12

def initialize(fields)
  @nats          = fields.fetch(:nats)
  @type          = Polyn::Naming.trim_domain_prefix(fields.fetch(:type))
  @consumer_name = Polyn::Naming.consumer_name(@type, fields[:source])
  @stream        = @nats.jetstream.find_stream_name_by_subject(@type)
  self.class.validate_consumer_exists!(@nats, @stream, @consumer_name)
  @psub          = @nats.jetstream.pull_subscribe(@type, @consumer_name)
  @serializer    = fields.fetch(:serializer)
end