class PikaQue::Publisher
Public Class Methods
new(opts = {})
click to toggle source
# File lib/pika_que/publisher.rb, line 6 def initialize(opts = {}) @opts = PikaQue.config.merge(opts) @codec = PikaQue::Util.constantize(@opts[:codec]) @connection = @opts[:connection] || PikaQue.connection @channel = @connection.create_channel @exchange = @channel.exchange(@opts[:exchange], @opts[:exchange_options]) end
Public Instance Methods
exchange_name()
click to toggle source
# File lib/pika_que/publisher.rb, line 24 def exchange_name @opts[:exchange] end
publish(msg, options = {})
click to toggle source
# File lib/pika_que/publisher.rb, line 14 def publish(msg, options = {}) to_queue = options.delete(:to_queue) options[:routing_key] ||= to_queue options[:content_type] ||= @codec.content_type msg = @codec.encode(msg) PikaQue.logger.info {"publishing <#{msg}> to [#{options[:routing_key]}]"} @exchange.publish(msg, options) end