【发布时间】:2011-10-27 08:15:57
【问题描述】:
我正在运行一个简单的瘦服务器,它将一些消息发布到不同的队列,代码如下:
require "rubygems"
require "thin"
require "amqp"
require 'msgpack'
app = Proc.new do |env|
params = Rack::Request.new(env).params
command = params['command'].strip rescue "no command"
number = params['number'].strip rescue "no number"
p command
p number
AMQP.start do
if command =~ /\A(create|c|r|register)\z/i
MQ.queue("create").publish(number)
elsif m = (/\A(Answer|a)\s?(\d+|\d+-\d+)\z/i.match(command))
MQ.queue("answers").publish({:number => number,:answer => "answer" }.to_msgpack )
end
end
[200, {'Content-Type' => "text/plain"} , command ]
end
Rack::Handler::Thin.run(app, :Port => 4001)
现在,当我运行服务器并执行 http://0.0.0.0:4001/command=r&number=123123123 之类的操作时 我总是得到重复的输出,比如:
“没有命令” “没有号码” “没有命令” “没有号码”
第一件事是为什么我会收到重复的请求?它与浏览器有关吗?因为当我使用 curl 时,我没有相同的行为,第二件事为什么我无法获得参数?
任何关于这种服务器的最佳实现的提示将不胜感激
提前致谢。
【问题讨论】: