Module: HotBunnies::Queue::Subscriber

Included in:
BlockingSubscriber
Defined in:
lib/hot_bunnies/queue.rb

Instance Method Summary collapse

Instance Method Details

#handle_message(consumer_tag, envelope, properties, body_bytes) ⇒ Object



133
134
135
136
137
138
139
140
# File 'lib/hot_bunnies/queue.rb', line 133

def handle_message(consumer_tag, envelope, properties, body_bytes)
  body = String.from_java_bytes(body_bytes)
  case @subscriber.arity
  when 2 then @subscriber.call(Headers.new(@channel, consumer_tag, envelope, properties), body)
  when 1 then @subscriber.call(body)
  else raise ArgumentError, 'Consumer callback wants no arguments'
  end
end

#on_message(&block) ⇒ Object

Raises:

  • (ArgumentError)


127
128
129
130
131
# File 'lib/hot_bunnies/queue.rb', line 127

def on_message(&block)
  raise ArgumentError, 'Message listener already registered for this subscriber' if @subscriber
  @subscriber = block
  start
end

#startObject



123
124
125
# File 'lib/hot_bunnies/queue.rb', line 123

def start
  # to be implemented by the host class
end