Created
March 12, 2019 15:58
-
-
Save igkuz/8cfe95d4e6d3407d56d9cd51ae9fb80d to your computer and use it in GitHub Desktop.
Ruby publisher for RabbitMQ queue with bunny gem
This file contains 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
#!/usr/bin/env ruby | |
# encoding utf-8 | |
require 'bunny' | |
require 'json' | |
STDOUT.sync = true | |
conn = Bunny.new(host: 'rmq', user: 'guest', pass: 'guest') | |
conn.start | |
ch = conn.create_channel | |
x = ch.exchange('work.exchange') | |
(1..10).each do |i| | |
x.publish( | |
{id: i, text: "I'm message #{i}"}.to_json, | |
routing_key: 'work.queue', | |
headers: { | |
content_type: 'application/json' | |
} | |
) | |
end | |
conn.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment