aio-libs / aiozmq

Asyncio (pep 3156) integration with ZeroMQ
aiozmq.readthedocs.org
BSD 2-Clause "Simplified" License
422 stars 56 forks source link

Any way to use rpc client in sync app? #147

Open derfenix opened 6 years ago

derfenix commented 6 years ago

Is there any way to make sync client to communicate aiozmq.rpc server? I meen any solution ready to use.

JelleZijlstra commented 6 years ago

aiozmq isn't intended for use in synchronous apps, but it should be possible to make async functions blocking by wrapping them in e.g. asyncio.run.

derfenix commented 6 years ago

I just meen if there any sync client uses the same messages format? I need to connect to rpc server on aiozmq.rpc from django app. So I need to choose - use aiozmq.rpc or use other package with ready sync clients.

akhilman commented 6 years ago

@derfenix seems like zmq_rpc is compatible with aoizmq.rpc.

derfenix commented 6 years ago

@akhilman Thanks, looks nice, but I've created a more simple version already, containing only client in one file. Just rewrite async version without async. May be this will be usefull for somebody else. https://gist.github.com/derfenix/f18e4a8f0ee9bad738c2b22106a3ad4d

akhilman commented 6 years ago

@derfenix thank you. I did my own non asyncio client using your code. https://gist.github.com/akhilman/6f4aa516a7317f36ebac427a9d392865 My client produces futures and doesn't block process until result() method called. It looks like:

futures = [rpc.method_one(), rpc.method_two()]
result_one, result_two = [fut.result() for fut in futures]
trollfot commented 1 year ago

@akhilman Hello, thank you very much for the code example. Would you have an up to date version on hand or the will to actually publish this as a package, so we could maintain it ?

Thank you !