aiozmq icon indicating copy to clipboard operation
aiozmq copied to clipboard

Any way to use rpc client in sync app?

Open derfenix opened this issue 5 years ago • 6 comments

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

derfenix avatar Jul 16 '18 19:07 derfenix

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.

JelleZijlstra avatar Jul 16 '18 21:07 JelleZijlstra

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.

derfenix avatar Jul 17 '18 08:07 derfenix

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

akhilman avatar Aug 25 '18 12:08 akhilman

@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

derfenix avatar Aug 27 '18 10:08 derfenix

@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]

akhilman avatar Aug 29 '18 16:08 akhilman

@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 !

trollfot avatar Mar 20 '23 19:03 trollfot