【问题标题】:Calling amqp message queque is not asynchronous调用amqp消息队列不是异步的
【发布时间】:2013-08-03 14:37:05
【问题描述】:

这是我的代码:

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...

【问题讨论】:

标签: ruby-on-rails ruby ruby-on-rails-3 rabbitmq amqp


【解决方案1】:

在我的前辈的帮助下,我成功地在 Rails 中实现了 Rabbitmq。如果有人有任何问题,我已经写了一篇博文here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-12
    • 2011-10-18
    • 2023-03-24
    • 2013-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-19
    相关资源
    最近更新 更多