我正在研究rabbitmq并尝试将一个方法从我的ruby on rails app推送到队列,我正在运行服务器端ruby脚本来读取队列并执行在有效负载中发送的方法。这是我的客户端代码。
module Rabbitesh
require 'amqp'
#debugger
def self.call_rabbits(payload,queue_name)
AMQP.start(:host => "localhost") 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
#end
end
end
end
end
现在我调用Rabbitmq函数
Rabbitesh::call_rabbits(obj,"welcome_mail")
其中“welcome_mail”是queue_name
这是服务器端脚本
require 'rubygems'
require 'amqp'
require 'daemons'
options = { :backtrace => true, :dir => '.', :log_output => true}
Daemons.run_proc('raabbitmq_daemon',options) do
AMQP.start(:host => "localhost") do |connection|
channel = AMQP::Channel.new(connection)
queue = channel.queue("welcome_mail")
Signal.trap("INT") do
connection.close do
EM.stop { exit }
end
end
puts " [*] Waiting for messages. To exit press CTRL+C"
queue.subscribe do |body|
UserMailers.welcome_organic(body).deliver
end
end
end
问题是当我的rails应用程序调用rabbitmq函数时,控制台在那里停止说“更新客户端属性”,虽然我将运行我的服务器端ruby脚本,但它不会读取队列并执行该过程。我无法理解代码中的错误,请帮助我。