0

我使用 EventMachine 已经有一段时间了,我真的觉得它很棒,因为它管理向我展示了我不必担心任何事情。但最近我发现了一个我无法理解的奇怪问题

这里只是告诉

我有 Eventmachine 循环,看起来像这样

 EventMachine::run {     
    EventMachine::add_periodic_timer(10) do
         EventMachine::defer(@operation_block,@callback_block)
    end
 } 

这里我的操作块看起来像(下面使用 amqp 使用胡萝卜宝石的代码)

@operation_block = Proc.new {
              begin   
              puts "Initiating the queue"
              @carrot ||= Carrot.new(:host => localhost)
              @queue ||= @carrot.queue("my_queue")
              puts "The Queue is Poping the message"

              if @queue.pop
                  [MY LOGIC HERE]
                  $input_to_callback = "SUCCESS" ## IF LOGIC GET EVALUATED WITHOUT ERROR ELSE WILL SET TO FAIL 
                else
                  $input_to_callback = "NOTHING TO PROCESSES"      
                end  
             rescue 
                puts e
                retry!   
             end    
             $input_to_callback 

          }

这里我的回调块看起来像

@callback_block = Proc.new {|operation_block_output|
   if operation_block_output == "SUCCESS"
      puts "YAHOOOOOOOOO SUCCESS"
   elsif operation_block_output == "NOTHING TO PROCESSES"
      puts "BOO Nothing to processes"
   else  
      puts "FAIL ALARM"
   end      
 }

现在问题来了,代码虽然按照它应该的方式工作,直到发生不好的事情我的意思是

现在假设我运行上面的代码

我有一个队列集名称“my_queue”,或者如果它不存在,它将创建一个队列最初是空的

这是我在控制台上得到的输出

启动队列

队列正在弹出消息

BOO 对进程没有任何影响

当我根据消息在控制台中构建输出更改时

现在的麻烦

如果我暂时关闭我的 AMQP 服务器这里的输出(显示我的意思)

启动队列

Broken Pipe => Error That Caught in begin rescue block in operation block

现在启动 AMQP 服务器

代码似乎永远不会从当前出现错误的行向前移动,这意味着我似乎从未打印过该行

队列正在弹出消息

不仅发生了重试的当前延迟,而且在 Timer 时间刚刚过去之后启动的新延迟操作块,即后续调用操作块的方法似乎永远不会向前移动并进行处理,并且总是只打印以下输出

Initiating the queue

只是似乎永远不会前进(卡住)并进行处理,即从队列中获取消息并相应地进行处理,并且所有其他内容(因为 AMQP 服务器现在正在运行)

谢谢

4

1 回答 1

0

Aman Gupta 已回答上述问题 https://github.com/eventmachine/eventmachine/issues/127#issuecomment-535210

于 2011-06-21T06:55:58.893 回答