Class: MessageQueue::Adapters::Bunny::Connection::Producer

Inherits:
Producer
  • Object
show all
Defined in:
lib/message_queue/adapters/bunny/producer.rb

Instance Attribute Summary collapse

Attributes inherited from Producer

#connection, #options

Instance Method Summary collapse

Methods inherited from Producer

#default_options, #dump_object

Methods included from OptionsHelper

#compute_values, #deep_clone

Constructor Details

#initialize(connection, options = {}) ⇒ Producer

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.



23
24
25
26
27
28
29
30
31
32
33
# 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

Instance Attribute Details

#exchangeObject (readonly)

Returns the value of attribute exchange.



2
3
4
# File 'lib/message_queue/adapters/bunny/producer.rb', line 2

def exchange
  @exchange
end

#exchange_nameObject (readonly)

Returns the value of attribute exchange_name.



3
4
5
# File 'lib/message_queue/adapters/bunny/producer.rb', line 3

def exchange_name
  @exchange_name
end

#exchange_optionsObject (readonly)

Returns the value of attribute exchange_options.



3
4
5
# File 'lib/message_queue/adapters/bunny/producer.rb', line 3

def exchange_options
  @exchange_options
end

#exchange_typeObject (readonly)

Returns the value of attribute exchange_type.



3
4
5
# File 'lib/message_queue/adapters/bunny/producer.rb', line 3

def exchange_type
  @exchange_type
end

#message_optionsObject (readonly)

Returns the value of attribute message_options.



4
5
6
# File 'lib/message_queue/adapters/bunny/producer.rb', line 4

def message_options
  @message_options
end

Instance Method Details

#publish(object, options = {}) ⇒ Object



35
36
37
38
39
# 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