试用RabbitMQ + AMQP

Friday, July 2, 2010

考虑在项目中使用消息队列, 所有试用了一下RabbitMQ + AMQP

1, 安装 sudo apt-get install rabbitmq-server 装完自动就启动了

2, 测试 RabbitMQ装在测试服务器 在本机新建来个脚本来测试一下

# vim publish.rb
require "rubygems"
require "mq"
Thread.new {AMQP.start(:host => '192.168.1.5')}
q = MQ.queue('my_queue')
i = 0
while true
  i += 1
  q.publish("Hello, World #{i}")
  sleep(1)
end



require "rubygems"
require "mq"

AMQP.start(:host => '192.168.1.5') do
  q = MQ.queue('my_queue')
  #q.subscribe do |msg|
  q.pop do |msg|
    puts "#{Time.now}: #{msg}" if msg
    q.pop
  end
end

运行两个脚本就可以看到结果了!~

This entry was tagged RabbitMQ and Ruby

comments powered by Disqus

© 2009-2013 lxneng.com. All rights reserved. Powered by Pyramid

go to Top