# Non-persistent ClusterRpcProxy

**URL:** <https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350>\
**Category:** Uncategorized\
**Created:** [September 30, 2018, 5:06am UTC](https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350 "2018-09-30T05:06:45Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![arnoldw](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@arnoldw](https://discourse.nameko.io/u/arnoldw)\
**Post date:** [September 30, 2018, 5:06am UTC](https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350/1 "2018-09-30T05:06:45Z")

</div>

Hi All,

I am developing an application that will handle large stream of videos/images and process them.  
I found nameko is quite easy to use and it is quite good so far.  
But, I would like to further decrease the message processing time, and I have been reading threads related to this. What I am still trying to understand is to make the message non-persistent and therefore can make RabbitMQ runs faster.  
I understand that the deliver\_mode has been exposed in nameko library. But, I do not understand how to set this parameter when I use an RPC call by using ClusterRpcProxy.  
I tried several things, but it did not achieve what I wanted (i.e. to make the message non-persistent).  
Some of the things that I tried but not successful:

> rpc = ClusterRpcProxy(config, delivery\_mode = 1)

> from kombu import Exchange  
> Exchange.delivery\_mode = 1

> config = {  
> ‘AMQP\_URI’: AMQP\_URI  
> ‘delivery\_mode’: 1  
> }  
> cluster\_rpc = ClusterRpcProxy(config)

Could someone help me? Did I miss something obvious here?

Best Regards,  
Arnold

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [October 2, 2018, 10:08am UTC](https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350/2 "2018-10-02T10:08:38Z")

</div>

Hi Arnold,

In the current stable release it’s not possible to configured the standalone proxy in this way.

However, the standalone proxy has been significantly refactored by the work in [https://github.com/nameko/nameko/pull/542](https://github.com/nameko/nameko/pull/542). These changes are about to hit PyPI as a pre-release version.

Using the pre-release version you will be able to do exactly as in your first attempt:

```auto
rpc = ClusterRpcProxy(config, delivery_mode=1)

```

We would be grateful for some feedback if you start to use this pre-release version!

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [October 2, 2018, 9:04pm UTC](https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350/3 "2018-10-02T21:04:42Z")

</div>

Pre-release 3.0.0rc0 is now on PyPI.

You can install it with `pip install --pre nameko`

---

<div class="post-metadata">

**Author:** ![arnoldw](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@arnoldw](https://discourse.nameko.io/u/arnoldw)\
**Post date:** [October 3, 2018, 7:33pm UTC](https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350/4 "2018-10-03T19:33:07Z")

</div>

Thanks Matt! I am still working on the other parts. I shall update you soon once I start looking at it.

---

<div class="post-metadata">

**Author:** ![arnoldw](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@arnoldw](https://discourse.nameko.io/u/arnoldw)\
**Post date:** [October 5, 2018, 8:48pm UTC](https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350/5 "2018-10-05T20:48:17Z")

</div>

Hi Matt,

I started looking at this, I did the `pip install --pre nameko`  
Then I ran my service: `nameko run myservice`, I received the following error:

```
from nameko.rpc import rpc, ServiceProxy, ReplyListener
ImportError: cannot import name ServiceProxy
```

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [October 6, 2018, 10:16pm UTC](https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350/6 "2018-10-06T22:16:49Z")

</div>

For what reason are you importing ServiceProxy directly? It’s a semi-internal part of the old implementation that had been refactored away.

If you can post some code it would help

---

<div class="post-metadata">

**Author:** ![arnoldw](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@arnoldw](https://discourse.nameko.io/u/arnoldw)\
**Post date:** [October 13, 2018, 10:18am UTC](https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350/7 "2018-10-13T10:18:59Z")

</div>

Hi Matt,

Sorry for the late response. I followed the code from: [https://groups.google.com/forum/#!topic/nameko-dev/XE-uarCEV00](https://groups.google.com/forum/#!topic/nameko-dev/XE-uarCEV00) to make a dynamic service call using RPCProxy.

```
class RpcProxyFactory(object):

    def __init__ (self, worker_ctx, reply_listener):
        self.worker_ctx = worker_ctx
        self.reply_listener = reply_listener

    def __call__ (self, target_service):
        return ServiceProxy(self.worker_ctx, target_service, self.reply_listener)

class DynamicRpcProxy(DependencyProvider):
    rpc_reply_listener = ReplyListener()

    def get_dependency(self, worker_ctx):
        return RpcProxyFactory(worker_ctx, self.rpc_reply_listener)
```

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [October 14, 2018, 11:10am UTC](https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350/8 "2018-10-14T11:10:59Z")

</div>

Ah, interesting. I had forgotten about this use-case.

In the refactored code you _almost_ get the “dynamic” proxy behaviour for free. I say almost because the `RpcProxy` requires that you provide a target service name and pre-populates it on the object that is returned. If that argument became optional, you could use the normal `RpcProxy` “dynamically” by simply not providing a target service name when declaring it.

I think this is a sufficiently common request that we should make that change. I’ll try and get that done and cut a new pre-release.

If you need something in the mean time, take a look at overriding the constructor and `get_dependency` methods of the `RpcProxy`

---

<div class="post-metadata">

**Author:** ![arnoldw](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@arnoldw](https://discourse.nameko.io/u/arnoldw)\
**Post date:** [October 14, 2018, 8:59pm UTC](https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350/9 "2018-10-14T20:59:22Z")

</div>

Thanks Matt for responding.

I will wait for the new pre-release to enable me initialize `RpcProxy` by doing “`proxy = RpcProxy()`” in a service class.

In the mean time, I will look the constructor and get\_dependency that you suggested. I suppose I only need to find the replacement of `ServiceProxy` in the ` __call__ ` function, is this correct?

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [October 29, 2018, 11:01pm UTC](https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350/10 "2018-10-29T23:01:07Z")

</div>

Sorry for the slow reply @arnoldw.

I’ve opened a [PR](https://github.com/nameko/nameko/pull/585) with these changes against the v3.0.0-rc branch. Once they land I’ll cut a new pre-release.

---

<div class="post-metadata">

**Author:** ![arnoldw](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@arnoldw](https://discourse.nameko.io/u/arnoldw)\
**Post date:** [November 2, 2018, 9:42am UTC](https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350/11 "2018-11-02T09:42:30Z")

</div>

Thanks @mattbennett! I look forward to testing the pre-release!

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [November 19, 2018, 4:44pm UTC](https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350/12 "2018-11-19T16:44:38Z")

</div>

@arnoldw 3.0.0-rc1 has been released to PyPI

---

<div class="post-metadata">

**Author:** ![arnoldw](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@arnoldw](https://discourse.nameko.io/u/arnoldw)\
**Post date:** [December 7, 2018, 9:13pm UTC](https://discourse.nameko.io/t/non-persistent-clusterrpcproxy/350/13 "2018-12-07T21:13:54Z")

</div>

Thanks @mattbennett! I will look into it soon.
