2

I am trying to replace the delayed_job implementaion for RabbitMQ and AMQP. Presently I am using ActionMailer Model to send emails. I have different methods to send for different type of Events. I am planning to replace it with the RabbitMQ and AMQP. After going through couple of AMQP examples I have written a simple module or helper,I not sure whether its correct or not and I am struggling to figure out how wrap the RabbitMQ around actionmailer. Here is the module which I wrote

module rabbitesh
  require 'amqp'

  def call_rabbits(payload,queue_name)
    AMQP.start(:host => CONFIG['RABBIT_HOST']) do |connection|
      channel = AMQP::Channel.new(connection)
      queue = channel.queue(queue_name)
      channel.default_exchange.publish(payload, :routing_key => queue.name)
      EM.add_timer(0.01) do
        connection.close do
          EM.stop { exit }
        end
      end
    end
  end

end

Kindly provide some heads up to achieve this.

4

0 回答 0