Home | Mirror | Search |
目錄
running on 127.0.0.1 (localhost) on port 5672 (standard AMQP port).
$ sudo apt-get install rabbitmq-server
sudo apt-get install python-setuptools python-pip git-core sudo pip install pika sudo easy_install pika
$ sudo gem install amqp
例 57.1. Ruby on RabbitMQ
subscriber.rb
$ cat subscriber.rb require 'rubygems' require 'amqp' EM.run { amq = MQ.new amq.queue("logins").subscribe do |login| puts login end }
producer.rb
$ cat producer.rb require 'rubygems' require 'amqp' EM.run { amq = MQ.new queue = amq.queue("logins") %w[scott nic robi].each { |login| queue.publish(login) } }
test
$ ruby subscriber.rb $ ruby producer.rb