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

Returns a new instance of Binding.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/msgr/binding.rb', line 16

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

Instance Method Details

#deleteObject



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

def delete
  release
  queue.delete
end

#purge(release: true) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/msgr/binding.rb', line 41

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

  queue.purge

  subscribe if release
end

#releaseObject



32
33
34
# File 'lib/msgr/binding.rb', line 32

def release
  subscription.cancel
end