Sha256: 498b7f1eddec8602f51fbc0f12af1e520a6050923f195967a7c5983bd5a4ba79

Contents?: true

Size: 800 Bytes

Versions: 1

Compression:

Stored size: 800 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

1 entries across 1 versions & 1 rubygems

Version Path
cony-2.0.1 lib/cony/amqp_connection_handler.rb