Sha256: c9c8179857b45c1a87e81ddfc442b81f25fbb3ba32a5713e16a470e47488d337

Contents?: true

Size: 786 Bytes

Versions: 5

Compression:

Stored size: 786 Bytes

Contents

require 'bunny'
require 'json'

module Cony
  class AMQPConnectionHandler

    def initialize(config)
      @config = config
    end

    def publish(message, routing_key)
      Bunny.run(@config) do |connection|
        exchange = connection.exchange(@config[:exchange], type: :topic, durable: Cony.config.durable)
        exchange.publish(message.to_json,
                         key: routing_key,
                         mandatory: false,
                         immediate: false,
                         persistent: Cony.config.durable,
                         content_type: 'application/json')
      end
    rescue => error
      Airbrake.notify_or_ignore(error) if defined?(Airbrake)
      Rails.logger.error("#{error.class}: #{error}") if defined?(Rails)
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cony-1.4.1 lib/cony/amqp_connection_handler.rb
cony-1.4.0 lib/cony/amqp_connection_handler.rb
cony-1.3.0 lib/cony/amqp_connection_handler.rb
cony-1.2.0 lib/cony/amqp_connection_handler.rb
cony-1.1.1 lib/cony/amqp_connection_handler.rb