class MessageQueue::Adapters::Bunny::Connection::Producer

Attributes

exchange[R]
exchange_name[R]
exchange_options[R]
exchange_type[R]
message_options[R]

Public Class Methods

new(connection, options = {}) click to toggle source

Public: Initialize a new Bunny producer.

connection - The Bunny Connection. options - The Hash options used to initialize the exchange

of a producer:
:exchange -
   :name    - The String exchange name.
   :type    - The Symbol exchange type.
   :durable - The Boolean exchange durability.
:message -
   :routing_key - The String message routing key.
   :persistent  - The Boolean indicate if the
   message persisted to disk .
Detailed options see
https://github.com/ruby-amqp/bunny/blob/master/lib/bunny/exchange.rb.

Returns a Publisher.

Calls superclass method MessageQueue::Producer::new
# File lib/message_queue/adapters/bunny/producer.rb, line 23
def initialize(connection, options = {})
  super

  @exchange_options = self.options.fetch(:exchange)
  @exchange_name = exchange_options.delete(:name) || (raise "Missing exchange name")
  @exchange_type = exchange_options.delete(:type) || (raise "Missing exchange type")

  @message_options = self.options.fetch(:message)

  @exchange = connection.connection.default_channel.send(exchange_type, exchange_name, exchange_options)
end

Public Instance Methods

publish(object, options = {}) click to toggle source
# File lib/message_queue/adapters/bunny/producer.rb, line 35
def publish(object, options = {})
  options = message_options.merge(default_options).merge(options)
  object = dump_object(object)
  exchange.publish(object, options)
end