我正在使用 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 从未收到数据。