Comments (6)
Completely agree that this should be possible. We are generally inconsistent about exposing delivery and other messaging options and to callers and there have been a number of issues related to it.
I like Option B, because it allows us to keep the simple invocation in the normal case. If you really needed per-call options you could do it with a locking context-manager around the invocation.
Are there other AMQP options/properties we should expose here as well?
On a related note we have AMQP publishing code scattered all over the codebase, and it's all pretty similar. The following all wrap a kombu publisher and pass slightly different options to it:
nameko.standalone.event_dispatcher
nameko.messaging.Publisher.get_dependency
nameko.rpc.Responder.send_response
nameko.rpc.MethodProxy._call
It feels like we should have a nameko.amqp
module that consolidates all this repeated code.
from nameko.
n.rpc.greeting_service.set_delivery_options
is problematic because we can't distinguish it from an rpc call to set_delivery_options
is the main use case the standalone proxy or injected rpc proxies? i wonder if a better option is to make it easy to subclass the extension and set these options there
from nameko.
Subclassing is nice but tricky to do in this case because MethodProxy
is quite buried. You'd have to subclass ServiceProxy
as well, and you'd have to do it for each permutation of options you wanted.
Since this is RPC we can probably get away with using a property. Something called delivery_options
is unlikely to be a remote method.
from nameko.
hm. elsewhere we work pretty hard to not infringe on "user namespaces", so would prefer to avoid. there might be workarounds (e.g off the top of my mind set_delivery_options(rpc_proxy, options)
, though with some thought we might be able to come up with something nicer)
i didn't mean to just say "subclass and override yourself", but rather for us to see if we can tweak/reorg the classes and their interactions to make it fairly straightforward to create a subclass that changes rabbit options
from nameko.
I've got another proof of concept ready where all the delivery options are provided when instantiating the service proxy. I think I found all the places where those options could be applied and the only real trouble is ensuring that delivery options of responses follow those of requests.
In addition to that I extended @rpc decorator to allow providing delivery options for responses specifically. The need for us was to allow defining compression on message for some methods only - the ones that return large lists of entries. So it made sense that the service decides whether to apply compression or not.
I will push both later today (will still be WIP). Unit tests are pain though, cause requests cannot be sniffed as easily as response messages (nameko tests suite only supports sniffing responses).
In regard to other AMQP options, there are more of course, but those 3 I mentioned cover the majority of use cases and they are the ones fully supported (virtually or natively) by other kombu transports (should you want to support them later).
from nameko.
So my new proposal is as follows. When creating ServiceRpcProxy or calling on dependency provider to get such proxy, developer can provide delivery_options
attribute in order to override kombu's defaults whenever interacting with a target service.
If, for some reason, different set of attributes is required for specific calls, developer can just create another proxy with different configuration.
Ideally, whatever parameters are being applied to the request, should also be applied to the response message.
In some cases, we'd like to be able to override those options for all responses from a particular method. For example one that returns large chunks of data (compression).
Sample usage:
large_msg_opt = {'compression': 'gzip', 'delivery_mode': 'transient'}
fast_msg_opt = {'delivery_mode': 'transient', 'timeout': 5}
class Service(object):
name = "service"
@rpc
def echo(self, arg):
return arg
@rpc(delivery_options=large_msg_opt)
def echo_compressed(self, arg):
return arg
with ServiceRpcProxy('service', rabbit_config, delivery_options=fast_msg_opt) as rpc_proxy:
rpc_proxy.echo(test_data)
rpc_proxy.echo_compressed(test_data)
rpc_proxy.echo.async(test_data)
rpc_proxy.echo_compressed.async(test_data)
Initial development, far from finished, but you may get some idea what I'm trying to achieve:
master...astawiarski:custom-delivery
from nameko.
Related Issues (20)
- nameko.exceptions.UnknownService: Unknown service `service_x`
- nameko.exceptions.UnknownService: Unknown service `service_x` HOT 2
- Incompatible versions in the resolved dependencies between Nameko and Celery in Kombu HOT 4
- Use another augmented assignment statement HOT 1
- Check for existing key HOT 1
- Should ipython and bpython be listed in some configuration files? HOT 1
- Why using dnspython 1.x instead of 2.x ? HOT 8
- need upgrade to support python 3.10 HOT 2
- Publisher crashing when exchange is provided and RabbitMQ is down
- Nameko crashes when consuming illegal messages HOT 6
- [ DOUBT ] Events Pub / Sub - How can I make a consumer only run one event at a time
- from nameko.rpc import rpc class GreetingService: name = "greeting_service" def hello(self, name): return "Hello, {}!".format(name)
- Timer work on master process or every process? HOT 2
- dnspython dependency version overly restrictive HOT 3
- "verify_amqp_uri" in the module "nameko.amqp.utils" had been removed? HOT 2
- Should HttpRequestHandler print out the exception to the browser? HOT 2
- nameko multiprocess problem HOT 1
- Do you die? we need you to improve Nameko Library HOT 5
- DB Migrations not working with Flask-Migrate HOT 2
- Linking nameko and golang by RPC HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nameko.