我使用Ubuntu14.04,軌5,RabbitMQ的(服務器3.6.5)時,兔子2.5.1RabbitMQ的超時::錯誤:IO超時讀7個字節
我實現兔至者地位,並試圖測試它。
我寫了下一個Ruby腳本:
def rabbit_test
s_time = Time.current
10_000.times do |n|
Mq::RabbitService.new('test_queue').publish(n.to_s)
end
p "###############################"
p "RabbirMQ Diff: #{Time.current - s_time}"
p "###############################"
end
其中Mq::RabbitService
服務包括初始化兔子,連接,創建隊列等
它的其他終端我跑
Mq::RabbitService.new('test_queue').subscribe
用於啓動它的工作好,但我只能推送827條消息(我不知道837爲什麼,但它總是相同的數字)。
之後,我的出版商引發錯誤:
[8] pry(main)> rabbit_test
E, [2016-08-19T15:17:02.445820 #6409] ERROR -- #<Bunny::Session:0x6fb39858 [email protected]:5672, vhost=/, addresses=[192.168.1.67:5672]>: Got an exception when receiving data: IO timeout when reading 7 bytes (Timeout::Error)
Timeout::Error: IO timeout when reading 7 bytes
from /home/oleg/.rvm/gems/ruby-2.3.1/gems/bunny-2.5.1/lib/bunny/cruby/socket.rb:52:in `rescue in read_fully'
而且我已經試過:添加新用戶管理員權限,試圖添加IP代替localhost
地址(如192.168.0.11
)結果是相同的。
EDITED
我用我的服務RabbitMQ的連接Mq::RabbitService gist
但
def rabbit_test
s_time = Time.current
1_000.times do |n|
connection = Bunny.new(host: '192.168.1.67', port: 5672, user: 'oleg', password: '111111').start
channel = connection.create_channel
channel.queue('queue_name', auto_delete: true)
exchange = channel.default_exchange
exchange.publish(n.to_s, routing_key: 'queue_name')
channel.close
end
p "###############################"
p "RabbirMQ Diff: #{Time.current - s_time}"
p "###############################"
end
不工作太
也許有人知道我做錯了什麼?
謝謝
您是否自己創建'Mq :: RabbitService'或者它是寶石?如果是你自己的班級,你可以把這個課程的要點連接起來嗎? – slowjack2k
您可以在編輯標記 –
後檢查它是否可以將連接移到循環之外?不確定它是否與問題有關,但爲什麼每次都創建一個新的連接? – theMayer