def _process_request(self, request, message): """Process incoming request.""" LOG.debug("Start processing request {0}.".format(request)) # get the correlation_id message property try: correlation_id = message.properties['correlation_id'] except KeyError: LOG.error("The 'correlation_id' message property is missing.") return else: LOG.debug("Correlation id: {0}".format(correlation_id)) # get the reply_to message property try: reply_to = message.properties['reply_to'] except KeyError: LOG.error("The 'reply_to' message property is missing.") return else: LOG.debug("Reply to: {0}".format(reply_to)) # execute function try: LOG.debug("Call function with args {!r}, keywords {!r}".format( request.func_args, request.func_keywords)) result = self._func_dict[request.func_name]( *request.func_args, **request.func_keywords) except Exception as e: LOG.error("Exception happened: {0}".format(e)) response = pr.RpcResponse(e) else: LOG.debug("Result: {!r}".format(result)) response = pr.RpcResponse(result) LOG.debug("Publish response: {0}".format(response)) with kombu.producers[self._conn].acquire(block=True) as producer: exchange = self._make_exchange(reply_to, durable=self._durable, auto_delete=True) producer.publish(body=response, serializer='pickle', exchange=exchange, correlation_id=correlation_id, declare=[exchange])
def test_creation_exception(self): response = protocol.RpcResponse(Exception('test')) self.assertIsInstance(response.result, Exception) self.assertTrue(response.is_exception)
def test_creation_default(self): response = protocol.RpcResponse('result') self.assertEqual(response.result, 'result') self.assertFalse(response.is_exception)