Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

139.2. ZeroMQ

ZeroMQ

$ sudo apt-get install zeromq-bin libzmq0 libzmq-dev libzmq-dbg
	

139.2.1. python-zeromq

sudo add-apt-repository ppa:chris-lea/zeromq
sudo apt-get update
        
sudo apt-get install python-zeromq
        

139.2.1.1. pyzmq

http://zeromq.github.com/pyzmq/

$ sudo apt-get install autoconf automake
$ sudo pip install pyzmq
		    
$ git clone git://github.com/zeromq/pyzmq.git
$ cd pyzmq
$ python setup.py configure --zmq=/path/to/zmq/prefix
$ python setup.py install
            
easy_install pyzmq
            

139.2.1.2. example

例 139.2. server.py

$ cat server.py
import zmq
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://127.0.0.1:5000")

while True:
    msg = socket.recv()
    print "Got", msg
    socket.send(msg)
                

例 139.3. client.py

$ cat client.py
import zmq
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://127.0.0.1:5000")

for i in range(10):
    msg = "msg %s" % i
    socket.send(msg)
    print "Sending", msg
    msg_in = socket.recv()
                

139.2.2. ruby zmq

sudo gem install zmq