/usr/share/doc/ruby-amqp/examples/publishing/publishing_a_one_off_message.rb is in ruby-amqp 0.9.5-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #!/usr/bin/env ruby
# encoding: utf-8
require "bundler"
Bundler.setup
$:.unshift(File.expand_path("../../../lib", __FILE__))
require 'amqp'
puts "=> Publishing and immediately stopping the event loop in the callback"
puts
# WARNING: this example is born out of http://bit.ly/j6v1Uz (#67) and
# by no means a demonstration of how you should go about publishing one-off messages.
# If durability is a concern, please read our "Durability and message persistence" guide at
# http://bit.ly/lQP1Al
EventMachine.run do
connection = AMQP.connect(:host => '127.0.0.1')
channel = AMQP::Channel.new(connection)
channel.on_error do |ch, channel_close|
puts "Channel-level error: #{channel_close.reply_text}, shutting down..."
connection.close { EventMachine.stop }
end
# topic exchange is used just as example. Often it is more convenient to use default exchange,
# see http://bit.ly/amqp-gem-default-exchange
exchange = channel.topic("a.topic", :durable => true, :auto_delete => true)
queue = channel.queue("a.queue", :auto_delete => true).bind(exchange, :routing_key => "events.#")
exchange.publish('hello world', :routing_key => "events.hits.homepage", :persistent => true, :nowait => false) do
puts "About to disconnect..."
connection.close { EventMachine.stop }
end
end
|