Esempio n. 1
def msg_reply(conf, msg_id, reply_q, connection_pool, reply=None,
              failure=None, ending=False, log_failure=True):
    """Sends a reply or an error on the channel signified by msg_id.

    Failure should be a sys.exc_info() tuple.

    with ConnectionContext(conf, connection_pool) as conn:
        if failure:
            failure = rpc_common.serialize_remote_exception(failure,

            msg = {'result': reply, 'failure': failure}
        except TypeError:
            msg = {'result': dict((k, repr(v))
                   for k, v in reply.__dict__.iteritems()),
                   'failure': failure}
        if ending:
            msg['ending'] = True
        # If a reply_q exists, add the msg_id to the reply and pass the
        # reply_q to direct_send() to use it as the response queue.
        # Otherwise use the msg_id for backward compatibilty.
        if reply_q:
            msg['_msg_id'] = msg_id
            conn.direct_send(reply_q, rpc_common.serialize_msg(msg))
            conn.direct_send(msg_id, rpc_common.serialize_msg(msg))
Esempio n. 2
    def _get_response(self, ctx, proxy, topic, data):
        """Process a curried message and cast the result to topic."""
        LOG.debug(_("Running func with context: %s"), ctx.to_dict())
        data.setdefault("version", None)
        data.setdefault("args", {})

            result = proxy.dispatch(ctx, data["version"], data["method"], data.get("namespace"), **data["args"])
            return ConsumerBase.normalize_reply(result, ctx.replies)
        except greenlet.GreenletExit:
            # ignore these since they are just from shutdowns
        except rpc_common.ClientException as e:
            LOG.debug(_("Expected exception during message handling (%s)") % e._exc_info[1])
            return {"exc": rpc_common.serialize_remote_exception(e._exc_info, log_failure=False)}
        except Exception:
            LOG.error(_("Exception during message handling"))
            return {"exc": rpc_common.serialize_remote_exception(sys.exc_info())}