ruby - How to do blocking subscribe using bunny RabbitMQ client? -
in java rabbitmq client can (code in ruby):
consumer = queueingconsumer.new(channel); channel.basicconsume(queue_name, true, consumer); consumer.nextdelivery.getbody
and third line blocks thread until message comes. how achieve in bunny client? can use block:
channel.queue('').bind(@x, :routing_key => rk).subscribe(block: true) |_, _, payload| # end
or non blocking pop:
delivery_info, properties, payload = q.pop
is there way achieve in jruby client using bunny? reason want after receiving message continue job in current context.
the call subscribe
blocking due passing :block => true
. if need access payload outside of block, can take advantage of ruby's scoping rules:
the_payload = nil queue = channel.queue('').bind(@x, :routing_key => rk) queue.subscribe(block: true) |delivery_info, _, payload| the_payload = payload channel.consumers[delivery_info.consumer_tag].cancel end # the_payload 1 received in block!
Comments
Post a Comment