class Urabbit::Publisher
Usage: begin
pubisher = Publisher.new( exchange_name: "courier_tracker", routing_key: "in.courier_statuses.created" ) publisher.publish(message)
rescue Publisher::Error => exception
puts exception.message puts exception.cause
end
Message is usually a JSON. Exception can contain a cause raised from Bunny.
Public Class Methods
new(opts)
click to toggle source
# File lib/urabbit/publisher.rb, line 16 def initialize(opts) exchange_type = opts[:exchange_type] || :topic exchange_name = opts[:exchange_name] || raise(Urabbit::Error.new("Please provide an 'exchange_name'")) @routing_key = opts[:routing_key] || raise(Urabbit::Error.new("Please provide a 'routing_key'")) @channel = Urabbit.create_channel @exchange = Bunny::Exchange.new( @channel, exchange_type, exchange_name, durable: true ) rescue Bunny::Exception raise Urabbit::Error.new("Error connecting to queue") end
Public Instance Methods
publish(message)
click to toggle source
# File lib/urabbit/publisher.rb, line 34 def publish(message) @exchange.publish(message, routing_key: @routing_key) rescue Bunny::Exception raise Urabbit::Error.new("Error communicating with queue") end