Exemplo n.º 1
0
        private void Reply(IReceivedMessage message, JsonTransportResponse response)
        {
            var reply   = message.CreateReply();
            var headers = AmqpRpc.CreateHeaders(null, response.Status);

            reply.Properties.Headers = headers;
            _log.Debug("Sending reply: {0}", response.Body);
            reply.Body = Json.Serialize(response.Body);
            reply.From = null;
            _messaging.Send(reply);
        }
Exemplo n.º 2
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));
        }