示例#1
0
        /// <summary>
        /// Call a remote procedure with a specified timeout
        /// </summary>
        /// <param name="endpoint">The endpoint to which to route the request</param>
        /// <param name="body">The request body</param>
        /// <param name="receiveTimeout">Timeout in ms, after which a null response is returned</param>
        /// <returns>The response</returns>
        public JContainer Call(string endpoint, JContainer body, int receiveTimeout)
        {
            var message = _messaging.CreateMessage();

            message.To                 = _target;
            message.ReplyTo            = _replyTo;
            message.Body               = Json.Serialize(body);
            message.Properties.Headers = AmqpRpc.CreateHeaders(endpoint, null);
            _messaging.Send(message);

            var reply = _messaging.Receive(receiveTimeout);

            if (AmqpRpc.GetStatusCode(reply) != 200)
            {
                throw new AmqpRpcError(Encoding.UTF8.GetString(reply.Body));
            }
            // TODO handle null reply (timeout)

            return(Json.Deserialize(reply.Body));
        }