def setUp(self): config = { 'moksha.livesocket': True, 'moksha.livesocket.backend': 'websocket', 'moksha.socket.notify': True, 'moksha.livesocket.websocket.port': 8009, "zmq_publish_endpoints": "tcp://*:6543", "zmq_subscribe_endpoints": "tcp://127.0.0.1:6543", "zmq_enabled": True, 'zmq_strict': False, } self.hub = CentralMokshaHub(config=config) self.topic = str(uuid4())
def main(options=None, consumers=None, producers=None, framework=True): """ The main MokshaHub method """ # If we're running as a framework, then we're strictly calling other # people's code. So, as the outermost piece of software in the stack, we're # responsible for setting up logging. # If we're not running as a framework, but as a library, then someone else # is calling us. Therefore, we'll let them set up the logging themselves. if framework: setup_logger('-v' in sys.argv or '--verbose' in sys.argv) config = {} if not options: if sys.argv[-1].endswith('.ini'): config_path = os.path.abspath(sys.argv[-1]) else: config_path = get_moksha_config_path() if not config_path: print NO_CONFIG_MESSAGE return cfg = appconfig('config:' + config_path) config.update(cfg) else: config.update(options) hub = CentralMokshaHub(config, consumers=consumers, producers=producers) global _hub _hub = hub def handle_signal(signum, stackframe): from moksha.hub.reactor import reactor if signum in [signal.SIGHUP, signal.SIGINT]: hub.stop() try: reactor.stop() except ReactorNotRunning: pass signal.signal(signal.SIGHUP, handle_signal) signal.signal(signal.SIGINT, handle_signal) log.info("Running the MokshaHub reactor") from moksha.hub.reactor import reactor reactor.run(installSignalHandlers=False) log.info("MokshaHub reactor stopped")
def test_open_and_close(self): """ Test that a central hub with a consumer can be closed.. ;) """ class TestConsumer(moksha.hub.api.consumer.Consumer): topic = "whatever" def consume(self, message): pass # Just a little fake config. config = dict( zmq_enabled=True, zmq_subscribe_endpoints='', zmq_published_endpoints='', ) central = CentralMokshaHub(config, [TestConsumer], []) central.close()
def test_dynamic_topic(self): """ Test that a topic can be set at runtime (not import time) """ class TestConsumer(moksha.hub.api.consumer.Consumer): topic = "bad topic" def __init__(self, *args, **kw): super(TestConsumer, self).__init__(*args, **kw) self.topic = "good topic" def consume(self, message): pass # Just a little fake config. config = dict( zmq_enabled=True, zmq_subscribe_endpoints='', zmq_published_endpoints='', ) central = CentralMokshaHub(config, [TestConsumer], []) # Guarantee that "bad topic" is not in the topics list. eq_(central.topics.keys(), ["good topic"])