Class: Msgr::Binding

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/msgr/binding.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#log, #log_name

Constructor Details

#initialize(connection, route, dispatcher) ⇒ Binding


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/msgr/binding.rb', line 9

def initialize(connection, route, dispatcher)
  @connection = connection
  @channel    = connection.channel(prefetch: route.prefetch)
  @route      = route
  @dispatcher = dispatcher
  @queue      = @channel.queue(route.name)

  route.keys.each do |key|
    log(:debug) { "Bind #{key} to #{queue.name}." }

    queue.bind @channel.exchange, routing_key: key
  end

  subscribe
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel


7
8
9
# File 'lib/msgr/binding.rb', line 7

def channel
  @channel
end

#connectionObject (readonly)

Returns the value of attribute connection


7
8
9
# File 'lib/msgr/binding.rb', line 7

def connection
  @connection
end

#dispatcherObject (readonly)

Returns the value of attribute dispatcher


7
8
9
# File 'lib/msgr/binding.rb', line 7

def dispatcher
  @dispatcher
end

#queueObject (readonly)

Returns the value of attribute queue


7
8
9
# File 'lib/msgr/binding.rb', line 7

def queue
  @queue
end

#routeObject (readonly)

Returns the value of attribute route


7
8
9
# File 'lib/msgr/binding.rb', line 7

def route
  @route
end

#subscriptionObject (readonly)

Returns the value of attribute subscription


7
8
9
# File 'lib/msgr/binding.rb', line 7

def subscription
  @subscription
end

Instance Method Details

#deleteObject


29
30
31
32
# File 'lib/msgr/binding.rb', line 29

def delete
  release
  queue.delete
end

#purge(release: true) ⇒ Object


34
35
36
37
38
39
40
# File 'lib/msgr/binding.rb', line 34

def purge(release: true)
  self.release if release

  queue.purge

  subscribe if release
end

#releaseObject


25
26
27
# File 'lib/msgr/binding.rb', line 25

def release
  subscription.cancel
end