Class: MarchHare::CallbackConsumer

Inherits:
BaseConsumer
  • Object
show all
Defined in:
lib/march_hare/consumers/base.rb

Direct Known Subclasses

BlockingCallbackConsumer

Instance Attribute Summary

Attributes inherited from BaseConsumer

#auto_ack, #consumer_tag

Instance Method Summary collapse

Methods inherited from BaseConsumer

#active?, #cancelled?, #gracefully_shut_down, #handleCancel, #handleCancelOk, #handleDelivery, #start, #terminated?

Constructor Details

#initialize(channel, queue, opts, callback) ⇒ CallbackConsumer

Returns a new instance of CallbackConsumer

Raises:

  • (ArgumentError)

94
95
96
97
98
99
100
# File 'lib/march_hare/consumers/base.rb', line 94

def initialize(channel, queue, opts, callback)
  raise ArgumentError, "callback must not be nil!" if callback.nil?

  super(channel, queue, opts)
  @callback = callback
  @callback_arity = @callback.arity
end

Instance Method Details

#cancelObject


110
111
112
113
114
115
116
117
118
119
# File 'lib/march_hare/consumers/base.rb', line 110

def cancel
  if @cancelling.get_and_set(true)
    false
  else
    @channel.basic_cancel(@consumer_tag)
    @cancelled.set(true)
    @terminated.set(true)
    true
  end
end

#deliver(headers, message) ⇒ Object


102
103
104
105
106
107
108
# File 'lib/march_hare/consumers/base.rb', line 102

def deliver(headers, message)
  if @callback_arity == 2 or @callback_arity < 0
    @callback.call(headers, message)
  else
    @callback.call(message)
  end
end