Created
October 10, 2020 10:07
-
-
Save carlok/8d86e35e2eb7c16cbbdcb14e3a521f84 to your computer and use it in GitHub Desktop.
Ruby Bunny AMQP RabbitMQ pop basic local worker example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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