noisyboiler / wampy

Websocket RPC and Pub/Sub for Python applications and microservices
Mozilla Public License 2.0
127 stars 24 forks source link

Implement __getitem__ on RPCProxy #27

Closed abulte closed 7 years ago

abulte commented 7 years ago

This lets me call "crossbar style" defined procedures easily from the RPC api.

For example:

client.rpc['com.example.foobar'](*args, **kwargs)
noisyboiler commented 7 years ago

Hi @abulte

Thanks for your suggestion here.

You raise an interesting point about "crossbar style", so let me give you a little background to wampy.

I initially prototyped wampy for an upstream project of mine: nameko_wamp. In nameko, the calling pattern is like the RpcProxy object you've tested out (thanks). But i realise this isn't intuitive for those already used to crossbar.

So, there is also the CallProxy object, which I intended to be used more "traditionally". To be honest, I haven't used it, and there may not even be test coverage for it.

I'm not sure whether there should be 2 separate call proxy objects (in which case i think your suggestion should probably be on the CallProxy, or maybe a single proxy object can accommodate both patterns.

I'll give this some proper thought and get back to you, but do let me know what you think.

Thanks again.

abulte commented 7 years ago

Hi @noisyboiler,

Thanks for the answer and the context. As a matter of fact, client.call('com.example.add2', 1, 2) works perfectly. This PR is probably void then. Maybe a line about that in the README?

Now to give you come context on my own, because it's quite related to yours: I'm currently benchmarking microservices solutions for a big project coming up. My language of ❤️ is Python, but I will need to work w/ some crazy people who think otherwise ;-) Thus I need a polyglot solution, hence Crossbar. But I really don't like the Crossbar Python API and I love the Nameko one. That's when I stumbled on nameko_wamp which seems capable of interfacing a Nameko set of microservices with some other services written in whatever language through Crossbar. Am I right on principle?

I did not yet test-drive nameko_wamp. I wanted to understand wampy first, since I saw it was a dependency. Hence my tests and PR. I validated that I could call some Crossbar Javascript procedures and exchange events to and from wampy, quite happy about that!

Any thought on what I'm trying to do? Makes sense? Already done that?

And BTW, thanks for this awesome project! I find the code very legible (it's not everyday that I make a PR a few hours after toying w/ a project) and the API quite clean.

noisyboiler commented 7 years ago

@abulte Thanks for the comments!

Great to hear that wampy has been put in action! I've not used it in conjunction with JS clients, so that is exciting to hear.

Regarding you benchmarking, i've used nameko services over HTTP (eventlet wsgi) combined with Flask (uwsgi) apps and the Flask ones are faster - but only to the tune of around 50ms. uwsgi is C of course, and eventlet is not. so this makes sense. Nameko really shines over AMQP/RPC, but it does appear that you're microservices will be talking over HTTP only?

Thanks again for your input!

abulte commented 7 years ago

Regarding you benchmarking, i've used nameko services over HTTP (eventlet wsgi) combined with Flask (uwsgi) apps and the Flask ones are faster - but only to the tune of around 50ms. uwsgi is C of course, and eventlet is not. so this makes sense.

ATM I'm not interested in performance benchmarking, just clean architecture and APIs. But it will come to that at one point ;-)

Nameko really shines over AMQP/RPC, but it does appear that you're microservices will be talking over HTTP only?

This is still fuzzy in my mind, but I was imagining using "native" RPC and PubSub capabilities of the different stacks as much as possible, not HTTP. So for Crossbar it would be WS, for Nameko AMQP. It seems a bit funky though to plug a RabbitMQ server just for the Nameko part and rely on Crossbar.io router to talk to the rest of the services... Something like that:

crossbar-wampy-nameko

Maybe I'll end just using Wampy for the Python part - since the API is appealing. Anyway, it's still long shot! I'll let you know if I'm starting to build real stuff w/ your products, I'll be glad to help.

noisyboiler commented 7 years ago

I have had similar thoughts in the past and would be interested to see how you get on. Feel free to ask questions whenever you like and I appreciate the feedback on the API, so thanks.