module Messaging::Producer

Public Instance Methods

publish(exchange, type, key, payload, options = {}) click to toggle source

Publish a payload to the specified exchange/key pair.

@param exchange [String] @param type [String] @param key [String] @param payload [Object] @return [Messaging::Producer] @api public

# File lib/messaging/producer.rb, line 14
def publish(exchange, type, key, payload, options = {})
  ex = producer_exchanges[exchange] ||=
    declare_exchange(producer_channel, exchange, type, config.exchange_options)

  log.debug("Publishing to exchange #{exchange.inspect} via #{key.inspect}")

  ex.publish(payload, options.merge({
    :exchange    => exchange,
    :routing_key => key
  }))

  self
end

Private Instance Methods

producer_channel() click to toggle source

@return [AMQP::Channel] @api private

# File lib/messaging/producer.rb, line 44
def producer_channel
  @producer_channel ||= open_channel(producer_connection)
end
producer_connection() click to toggle source

@return [AMQP::Connection] @api private

# File lib/messaging/producer.rb, line 38
def producer_connection
  @producer_connection ||= open_connection(config.publish_to)
end
producer_exchanges() click to toggle source

@return [Hash(String, AMQP::Exchange)] @api private

# File lib/messaging/producer.rb, line 32
def producer_exchanges
  @producer_exchanges ||= {}
end