Class: Cony::AMQPConnectionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/cony/amqp_connection_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ AMQPConnectionHandler

Returns a new instance of AMQPConnectionHandler.



6
7
8
# File 'lib/cony/amqp_connection_handler.rb', line 6

def initialize(config)
  @config = config
end

Instance Method Details

#publish(message, routing_key) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cony/amqp_connection_handler.rb', line 10

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
  Raven.capture_exception(error) if defined?(Raven)
  Rails.logger.error("#{error.class}: #{error}") if defined?(Rails)
end