我正在使用pyzmq在rrbroker.py和reworker.py之间传输消息。出于某种原因我得到了
worker:
Users/eric/Documents/Programming/JavaScript/NodeJS/urchin/urchin_worker.py in <module>()
111 while True:
112 try:
--> 113 message = socket.recv()
114 message = json.loads(message)#decode into JSON
115 print message
Exception TypeError: "'NoneType' object is not callable" in <zmq.core.socket.Socket object at 0x104ffc460> ignored
经纪人代码:
import zmq
context = zmq.Context()
frontend = context.socket(zmq.ROUTER)
backend = context.socket(zmq.DEALER)
frontend.bind("tcp://127.0.0.1:5559")
backend.bind("tcp://127.0.0.1:5560")
# Initialize poll set
poller = zmq.Poller()
poller.register(frontend, zmq.POLLIN)
poller.register(backend, zmq.POLLIN)
print 'starting Router-Dealer Broker...'
# Switch messages between sockets
while True:
socks = dict(poller.poll())
if socks.get(frontend) == zmq.POLLIN:
message = frontend.recv()
print 'passing message from frontend to backend'
print message
more = frontend.getsockopt(zmq.RCVMORE)
if more:
backend.send(message, zmq.SNDMORE)
else:
backend.send(message)
if socks.get(backend) == zmq.POLLIN:
message = backend.recv()
print 'passing message from backend to frontend'
print message
more = backend.getsockopt(zmq.RCVMORE)
if more:
frontend.send(message, zmq.SNDMORE)
else:
frontend.send(message)
经纪人日志:
passing message from frontend to backend
???0{pK???+E?5??
passing message from frontend to backend
passing message from frontend to backend
{'foo':'bar'}//data from client (connected to the broker's router port).
显而易见,我的经纪人一次向工人发送3个请求(这是正常的),但第一个数据包似乎是乱码,第二个数据包似乎是空的,第三个数据包最终包含我想要发送的数据第一名。
所以代理发送了数据包,但似乎worker.py从未收到数据。