[zmq] make publish address optional
It should be possible to use the zmq communication bus in a read-only
manner. Allow setting zmq-address-sub without zmq-address-pub.
Closes #2897178.
--- a/hooks/zmq.py Thu May 23 14:38:43 2013 +0200
+++ b/hooks/zmq.py Thu May 23 12:35:02 2013 +0200
@@ -33,16 +33,18 @@
def __call__(self):
config = self.repo.config
address_pub = config.get('zmq-address-pub')
- if not address_pub:
+ address_sub = config.get('zmq-address-sub')
+ if not address_pub and not address_sub:
return
from cubicweb.server import cwzmq
self.repo.app_instances_bus = cwzmq.ZMQComm()
- self.repo.app_instances_bus.add_publisher(address_pub)
+ if address_pub:
+ self.repo.app_instances_bus.add_publisher(address_pub)
def clear_cache_callback(msg):
self.debug('clear_caches: %s', ' '.join(msg))
self.repo.clear_caches(msg[1:])
self.repo.app_instances_bus.add_subscription('delete', clear_cache_callback)
- for address in config.get('zmq-address-sub'):
+ for address in address_sub:
self.repo.app_instances_bus.add_subscriber(address)
self.repo.app_instances_bus.start()
--- a/server/cwzmq.py Thu May 23 14:38:43 2013 +0200
+++ b/server/cwzmq.py Thu May 23 12:35:02 2013 +0200
@@ -78,7 +78,8 @@
self._subscribers.append(subscriber)
def publish(self, msg):
- assert self.publisher is not None, "can't publish without a publisher"
+ if self.publisher is None:
+ return
self.publisher.send(msg)
def start(self):