Skip to content

Instantly share code, notes, and snippets.

@carlok
Created October 10, 2020 10:07
Show Gist options
  • Save carlok/8d86e35e2eb7c16cbbdcb14e3a521f84 to your computer and use it in GitHub Desktop.
Save carlok/8d86e35e2eb7c16cbbdcb14e3a521f84 to your computer and use it in GitHub Desktop.
Ruby Bunny AMQP RabbitMQ pop basic local worker example
require "bunny"
# vhost create
# curl -u guest:guest -X PUT http://localhost:15672/api/vhosts/ckvh1
#
# push message in a vhost queue
# curl -i -u guest:guest -H "content-type:application/json" -X POST \
# http://localhost:15672/api/exchanges/ckvh1/amq.default/publish \
# -d '{"properties": {}, "routing_key": "aaa", "payload": "bbb", "payload_encoding": "string"}'
connection = Bunny.new("amqp://guest:guest@localhost/ckvh1", verify_peer: true, threaded: false)
connection.start
channel = connection.create_channel
queue = channel.queue('aaa', durable: true) # auto_delete: true,
# Declare a default direct exchange which is bound to all queues
# exchange = channel.exchange('')
loop do
queue.subscribe do |delivery_info, metadata, payload|
puts "delivery_info => #{delivery_info}, metadata => #{metadata}, payload => #{payload}"
end
end
connection.close # connection.stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment