Class: Warren::Subscription

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/warren/subscription.rb

Overview

Configures and wraps up subscriptions on a Bunny Channel/Queue

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel:, config:) ⇒ Subscription

Great a new subscription. Handles queue creation, binding and attaching consumers to the queues

Parameters:



17
18
19
20
21
22
# File 'lib/warren/subscription.rb', line 17

def initialize(channel:, config:)
  @channel = channel
  @queue_name = config&.fetch('name')
  @queue_options = config&.fetch('options')
  @bindings = config&.fetch('bindings')
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



8
9
10
# File 'lib/warren/subscription.rb', line 8

def channel
  @channel
end

Instance Method Details

#activate!Object

Ensures the queues and channels are set up to receive messages keys: additional routing_keys to bind



44
45
46
# File 'lib/warren/subscription.rb', line 44

def activate!
  establish_bindings!
end

#subscribe(consumer_tag) {|delivery_info, properties, payload| ... } ⇒ Bunny::Consumer

Subscribes to the given queue

Parameters:

  • consumer_tag (String)

    Identifier for the consumer

Yield Parameters:

  • delivery_info (Bunny::DeliveryInfo)

    Metadata about the delivery

  • properties (Bunny::MessageProperties)
  • payload (String)

    the contents of the message

Returns:

  • (Bunny::Consumer)

    The bunny consumer object



37
38
39
40
# File 'lib/warren/subscription.rb', line 37

def subscribe(consumer_tag, &block)
  channel.prefetch(10)
  queue.subscribe(manual_ack: true, block: false, consumer_tag: consumer_tag, durable: true, &block)
end