rabbitmq in ruby on mac not received消息

5ssjco0h  于 12个月前  发布在  Ruby
关注(0)|答案(1)|浏览(74)

我是rabbitmq的新手。我试着在mac上使用ruby和rabbitmq学习教程。我创建了两个.rb文件。
worker.rb

require 'bunny'
connection=Bunny.new
connection.start
channel= connection.create_channel
queue=channel.queue('hello')

begin
  puts ' Waiting for messages. To exit press CTRL+C'
  queue.subscribe(block: true) do |delivery_info, _properties, body|
  puts " [x] Received #{body}"
  # imitate some work
  sleep body.count('.').to_i
  puts ' [x] Done'
end
rescue Interrupt => _
  conn.close

  exit(0)
end

接收.rb

require 'bunny'
    connection=Bunny.new
    connection.start
    channel= connection.create_channel
    queue=channel.queue('hello')
    begin
      puts ' Waiting for messages. To exit press CTRL+C'
      queue.subscribe(block: true) do |_delivery_info, _properties, body|
        puts "  Received #{body}"
    end
rescue Interrupt => _
  conn.close

  exit(0)
end

rabbitmq服务器已打开。当我运行ruby new_task.rb时,我看到输出[x] Sent Hello World!,正如预期的那样。当我运行ruby worker. rb时。显示等待消息...但永远不会收到消息。有人能帮忙吗?

ygya80vv

ygya80vv1#

我建议仔细研究tutorial code,并将其与您编写的内容进行比较。
由于您没有提供new_task.rb的代码,因此我假设您使用的是显示为here的代码。该代码需要一个名为task_queue的队列,而您上面提供的代码使用了一个名为hello的队列。

相关问题