def test_declare_rpc_reply_queue_binding(self): poller = pika_poller.RpcReplyPikaPoller( self._pika_engine, self._exchange, self._queue, 1, None, self._prefetch_count, ) poller.start(None) poller.stop() declare_queue_binding_by_channel_mock = ( self._pika_engine.declare_queue_binding_by_channel) self.assertEqual(declare_queue_binding_by_channel_mock.call_count, 1) declare_queue_binding_by_channel_mock.assert_called_once_with( channel=self._poller_channel_mock, durable=False, exchange='rpc_reply_exchange', exchange_type='direct', queue='rpc_reply_queue', queue_expiration=12345, routing_key='rpc_reply_queue')
def get_reply_qname(self): """As result return reply queue name, shared for whole process, but before this check is RPC listener initialized or not and perform initialization if needed :return: String, queue name which hould be used for reply sending """ if self._reply_consumer_initialized: return self._reply_queue with self._reply_consumer_initialization_lock: if self._reply_consumer_initialized: return self._reply_queue # generate reply queue name if needed if self._reply_queue is None: self._reply_queue = "reply.{}.{}.{}".format( self._pika_engine.conf.project, self._pika_engine.conf.prog, uuid.uuid4().hex ) # initialize reply poller if needed if self._reply_poller is None: self._reply_poller = pika_drv_poller.RpcReplyPikaPoller( self._pika_engine, self._pika_engine.rpc_reply_exchange, self._reply_queue, 1, None, self._pika_engine.rpc_reply_listener_prefetch_count ) self._reply_poller.start(self._on_incoming) self._reply_consumer_initialized = True return self._reply_queue
def test_start(self): poller = pika_poller.RpcReplyPikaPoller( self._pika_engine, self._exchange, self._queue, self._prefetch_count, ) poller.start() self.assertTrue(self._pika_engine.create_connection.called) self.assertTrue(self._poller_connection_mock.channel.called)
def get_reply_qname(self, expiration_time=None): """As result return reply queue name, shared for whole process, but before this check is RPC listener initialized or not and perform initialization if needed :param expiration_time: Float, expiration time in seconds (like time.time()), :return: String, queue name which hould be used for reply sending """ if self._reply_consumer_initialized: return self._reply_queue with self._reply_consumer_initialization_lock: if self._reply_consumer_initialized: return self._reply_queue # generate reply queue name if needed if self._reply_queue is None: self._reply_queue = "reply.{}.{}.{}".format( self._pika_engine.conf.project, self._pika_engine.conf.prog, uuid.uuid4().hex ) # initialize reply poller if needed if self._reply_poller is None: self._reply_poller = pika_drv_poller.RpcReplyPikaPoller( pika_engine=self._pika_engine, exchange=self._pika_engine.rpc_reply_exchange, queue=self._reply_queue, prefetch_count=( self._pika_engine.rpc_reply_listener_prefetch_count ) ) self._reply_poller.start(timeout=expiration_time - time.time()) # start reply poller job thread if needed if self._poller_thread is None: self._poller_thread = threading.Thread(target=self._poller) self._poller_thread.daemon = True if not self._poller_thread.is_alive(): self._poller_thread.start() self._reply_consumer_initialized = True return self._reply_queue