Sha256: 2e9e38d5fcfe7ae76e7e1b8ad5fd09f0ee73c0f5bb562fe92bbbeab909f2c291

Contents?: true

Size: 798 Bytes

Versions: 4

Compression:

Stored size: 798 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|
        channel = connection.create_channel
        exchange = channel.topic(@config[:exchange], 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(error) if defined?(Airbrake)
      Rails.logger.error("#{error.class}: #{error}") if defined?(Rails)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cony-2.2.4 lib/cony/amqp_connection_handler.rb
cony-2.2.3 lib/cony/amqp_connection_handler.rb
cony-2.2.2 lib/cony/amqp_connection_handler.rb
cony-2.2.1 lib/cony/amqp_connection_handler.rb