smira / txZMQ

ZeroMQ bindings for Twisted
http://pypi.python.org/pypi/txZMQ/
Mozilla Public License 2.0
148 stars 55 forks source link

txzmq.ZmqREQConnection messageReceived code is returning weird results #76

Closed memetb closed 6 years ago

memetb commented 6 years ago

When I call the following code:

def prime_data(msg):
    print( msg )

poll = ZmqREQConnection(self.factory, ZmqEndpoint("connect", "127.0.0.1:5001))
poll.messageReceived = prime_data
poll.sendMsg(b"*")

I get the following output:

[b'\x7fs\x8d\xf1\xfa\x19G\x08\xbd\xff\x91\xcf\xcb\x14KB', b'', b'ACTUAL CONTENT OF MESSAGE...']

Comparing ZmqREPConnection's and ZmqREQConnection's implementations of messageReceived methods here and here, I'm wondering if there isn't a missing step for ZmqREQConnection's processing of incoming messages.

Perhaps I'm missing something obvious? This isn't exactly show stopper bug, but it does seems like an inconsistent API.

smira commented 6 years ago

From your example it's not quite clear what is going on, you should be connecting REQ to REP, and their implementations are not symmetric cause there's additional routing info passed.

You're not supposed to override messageReceived method, please take a look at the example code https://github.com/smira/txZMQ/blob/master/examples/req_rep.py

memetb commented 6 years ago

Oh, I see. Somehow I missed the addCallback subtlety which is different than the other socket types.

Thanks for the quick reply.