1. RabbitMQ
running on 127.0.0.1 (localhost) on port 5672 (standard AMQP port).
$ sudo apt-get install rabbitmq-server
1.1. rabbitmqctl - command line tool for managing a RabbitMQ broker
rabbitmqctl status
1.2. Python - Pika
sudo apt-get install python-setuptools python-pip git-core sudo pip install pika sudo easy_install pika
1.3. Ruby amqp
$ sudo gem install amqp
例 54.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
时间: 2024-10-01 01:47:24