Class: MessageQueue::Adapters::Bunny::Connection::Publisher
- Inherits:
-
Object
- Object
- MessageQueue::Adapters::Bunny::Connection::Publisher
- Defined in:
- lib/message_queue/adapters/bunny/publisher.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
-
#exchange_name ⇒ Object
readonly
Returns the value of attribute exchange_name.
-
#exchange_options ⇒ Object
readonly
Returns the value of attribute exchange_options.
-
#exchange_type ⇒ Object
readonly
Returns the value of attribute exchange_type.
-
#message_options ⇒ Object
readonly
Returns the value of attribute message_options.
Instance Method Summary collapse
-
#initialize(connection, options = {}) ⇒ Publisher
constructor
Public: Initialize a new Bunny publisher.
- #publish(payload, options = {}) ⇒ Object
Constructor Details
#initialize(connection, options = {}) ⇒ Publisher
Public: Initialize a new Bunny publisher.
connection - The Bunny Connection. options - The Hash options used to initialize the exchange
of a publisher:
: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 34 35 |
# File 'lib/message_queue/adapters/bunny/publisher.rb', line 23 def initialize(connection, = {}) @connection = connection = .dup @exchange_options = .fetch(:exchange) @exchange_name = .delete(:name) || (raise "Missing exchange name") @exchange_type = .delete(:type) || (raise "Missing exchange type") @message_options = .fetch(:message) @exchange = connection.connection.default_channel.send(exchange_type, exchange_name, ) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
2 3 4 |
# File 'lib/message_queue/adapters/bunny/publisher.rb', line 2 def connection @connection end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
2 3 4 |
# File 'lib/message_queue/adapters/bunny/publisher.rb', line 2 def exchange @exchange end |
#exchange_name ⇒ Object (readonly)
Returns the value of attribute exchange_name.
3 4 5 |
# File 'lib/message_queue/adapters/bunny/publisher.rb', line 3 def exchange_name @exchange_name end |
#exchange_options ⇒ Object (readonly)
Returns the value of attribute exchange_options.
3 4 5 |
# File 'lib/message_queue/adapters/bunny/publisher.rb', line 3 def @exchange_options end |
#exchange_type ⇒ Object (readonly)
Returns the value of attribute exchange_type.
3 4 5 |
# File 'lib/message_queue/adapters/bunny/publisher.rb', line 3 def exchange_type @exchange_type end |
#message_options ⇒ Object (readonly)
Returns the value of attribute message_options.
4 5 6 |
# File 'lib/message_queue/adapters/bunny/publisher.rb', line 4 def @message_options end |
Instance Method Details
#publish(payload, options = {}) ⇒ Object
37 38 39 |
# File 'lib/message_queue/adapters/bunny/publisher.rb', line 37 def publish(payload, = {}) exchange.publish(connection.serializer.dump(payload), .merge()) end |