Home | Mirror | Search

第 57 章 Message Queuing

目錄

1. RabbitMQ
1.1. rabbitmqctl - command line tool for managing a RabbitMQ broker
1.2. Python - Pika
1.3. Ruby amqp
2. ZeroMQ
2.1. python-zeromq
2.1.1. pyzmq
2.1.2. example
2.2. ruby zmq

Apache ActiveMQ

1. RabbitMQ

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

http://pika.github.com/

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
		

例 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
			

comments powered by Disqus