From 33fbd87975aec414cfe5c9eaa8435ddae076f91f Mon Sep 17 00:00:00 2001 From: Lianhao Lu Date: Thu, 8 Nov 2012 18:47:37 +0800 Subject: Added initialize_service_hook for rpc.Service. This fixes the collector part of the bug 1075463. Declaring a consumer topic on the same rpc connection after the consume thread has started would result the eventlet raise RuntimeError exception. So all the declaring work should be done before calling rpc.conn.consume_in_thread(). If the manager of a rpc.Service wants to declare topic consumers other than the default ones created by rpc.Service.start(), it could define the following hook in the manager class: def initialize_service_hook(self, service): # # Do initialization work after rpc connection is created and before # starting consuming thread. # Params: # service: handle to the rpc.Service instance. Change-Id: I80001c32ee4e51e394fed827c91ad5e1eb0f94dc --- openstack/common/rpc/service.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'openstack/common/rpc/service.py') diff --git a/openstack/common/rpc/service.py b/openstack/common/rpc/service.py index e572956..6b56ebb 100644 --- a/openstack/common/rpc/service.py +++ b/openstack/common/rpc/service.py @@ -57,6 +57,11 @@ class Service(service.Service): self.conn.create_consumer(self.topic, dispatcher, fanout=True) + # Hook to allow the manager to do other initializations after + # the rpc connection is created. + if callable(getattr(self.manager, 'initialize_service_hook', None)): + self.manager.initialize_service_hook(self) + # Consume from all consumers in a thread self.conn.consume_in_thread() -- cgit