Class: RabbitMQClient::QueueConsumer

Inherits:
DefaultConsumer
  • Object
show all
Defined in:
lib/jessica/rabbitmq_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(channel, block) ⇒ QueueConsumer

Returns a new instance of QueueConsumer.



55
56
57
58
59
# File 'lib/jessica/rabbitmq_client.rb', line 55

def initialize(channel, block)
  @channel = channel
  @block = block
  super(channel)
end

Instance Method Details

#handleDelivery(consumer_tag, envelope, properties, body) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/jessica/rabbitmq_client.rb', line 61

def handleDelivery(consumer_tag, envelope, properties, body)
  delivery_tag = envelope.get_delivery_tag
  message_body = String.from_java_bytes(body)
  # TODO: Do we need to do something with properties?
  case @block.arity
  when 1
    @block.call message_body
  when 2
    @block.call message_body, properties
  when 3
    @block.call message_body, properties, envelope
  end
  @channel.basic_ack(delivery_tag, false)
end