Giter Club home page Giter Club logo

Comments (6)

mattbennett avatar mattbennett commented on July 3, 2024

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.

davidszotten avatar davidszotten commented on July 3, 2024

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.

mattbennett avatar mattbennett commented on July 3, 2024

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.

davidszotten avatar davidszotten commented on July 3, 2024

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.

astawiarski avatar astawiarski commented on July 3, 2024

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.

astawiarski avatar astawiarski commented on July 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.