下面是我的代码:
class ParsepdfClient
#!/usr/bin/env ruby
# encoding: utf-8
require 'amqp'
require "rubygems"
require 'mq'
def self.test
EventMachine.run do
connection = AMQP.connect(:host => '127.0.0.1')
puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
channel = AMQP::Channel.new(connection)
queue = channel.queue("amqpgem.examples.helloworld", :auto_delete => true)
exchange = channel.direct("")
queue.subscribe do |payload|
sleep(1.minutes)
puts "Received a message: #{payload}. Disconnecting..."
connection.close { EventMachine.stop }
end
exchange.publish "Hello, world!", :routing_key => queue.name
end
end
end我使用Rabbitmq作为rails amqp gem的代理。现在我打电话给你:
从控制器执行ParsepdfClient.test命令。
根据我的理解,我的调用不应该休眠一分钟,但它会等待一分钟,然后输出
"Received a message: Hello, world!. Disconnecting..."然后它会执行控制器的其余代码。调用不应该是异步的吗?如果不是,我怎么才能使它异步呢?
我的意思是,它不应该在输出后执行控制器的其余代码
Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem...发布于 2013-09-29 06:14:37
在前辈的帮助下,我成功地在rails中实现了Rabbitmq。如果任何人有任何问题,我已经写了一个博客帖子here。
https://stackoverflow.com/questions/18033961
复制相似问题