Skip to content

Instantly share code, notes, and snippets.

@igkuz
Created March 12, 2019 15:58
Show Gist options
  • Save igkuz/8cfe95d4e6d3407d56d9cd51ae9fb80d to your computer and use it in GitHub Desktop.
Save igkuz/8cfe95d4e6d3407d56d9cd51ae9fb80d to your computer and use it in GitHub Desktop.
Ruby publisher for RabbitMQ queue with bunny gem
#!/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