Class: PikaQue::Publisher
- Inherits:
-
Object
- Object
- PikaQue::Publisher
- Defined in:
- lib/pika_que/publisher.rb
Instance Method Summary collapse
- #exchange_name ⇒ Object
-
#initialize(opts = {}) ⇒ Publisher
constructor
A new instance of Publisher.
- #publish(msg, options = {}) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Publisher
Returns a new instance of Publisher.
6 7 8 9 10 11 12 |
# 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 |
Instance Method Details
#exchange_name ⇒ Object
24 25 26 |
# File 'lib/pika_que/publisher.rb', line 24 def exchange_name @opts[:exchange] end |
#publish(msg, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/pika_que/publisher.rb', line 14 def publish(msg, = {}) to_queue = .delete(:to_queue) [:routing_key] ||= to_queue [:content_type] ||= @codec.content_type msg = @codec.encode(msg) PikaQue.logger.info {"publishing <#{msg}> to [#{[:routing_key]}]"} @exchange.publish(msg, ) end |