Skip to content

Commit

Permalink
Merge pull request #462 from bobh66/reuse_proxy_instance
Browse files Browse the repository at this point in the history
Set stopped flag to allow PollingQueueConsumer object reuse
  • Loading branch information
mattbennett committed Aug 22, 2017
2 parents c9ef868 + 47b4878 commit 14134e8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ Here you can see the full list of changes between nameko versions. Versions
are in form of *headline.major.minor* numbers. Backwards-compatible changes
increment the minor version number only.

Version TBD
-----------

Release: Pending

* Set stopped flag in register_provider() to allow PollingQueueConsumer
object reuse [fixes #462]


Version 2.6.0
-------------

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ Alexandre Héaumé (@aheaume)
Jesse Pollak (@jessepollak)
Miklos Vincze (@vmikki)
Yihang Yang (@mikegreen7892003)
Bob Haddleton (@bobh66)
3 changes: 2 additions & 1 deletion nameko/standalone/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PollingQueueConsumer(object):
consumer = None

def __init__(self, timeout=None):
self.stopped = False
self.stopped = True
self.timeout = timeout
self.replies = {}

Expand Down Expand Up @@ -119,6 +119,7 @@ def register_provider(self, provider):

self.queue = provider.queue
self._setup_consumer()
self.stopped = False

def unregister_provider(self, provider):
self.connection.close()
Expand Down
12 changes: 12 additions & 0 deletions test/standalone/test_rpc_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,18 @@ def test_cluster_proxy(container_factory, rabbit_manager, rabbit_config):
assert proxy.foobar.spam(ham=1) == 1


def test_cluster_proxy_reuse(container_factory, rabbit_manager, rabbit_config):
container = container_factory(FooService, rabbit_config)
container.start()

cluster_proxy = ClusterRpcProxy(rabbit_config)
with cluster_proxy as proxy:
assert proxy.foobar.spam(ham=1) == 1

with cluster_proxy as second_proxy:
assert second_proxy.foobar.spam(ham=1) == 1


def test_cluster_proxy_dict_access(
container_factory, rabbit_manager, rabbit_config
):
Expand Down

0 comments on commit 14134e8

Please sign in to comment.