示例#1
0
        private async Task SendResponseMessage(QueueBasedApiContext context)
        {
            var clientEtag = (string)context.Parameter["ETag"];

            var brokerProperties = new JObject
            {
                ["CorrelationId"] = context.CorrelationId
            };

            var message = new JObject
            {
                ["ResultCode"] = context.ResultCode.ToString(),
                ["Content"]    = context.Result
            };

            var serverEtag = (string)context.Result["Meta"]["Hash"];

            message["ETag"] = serverEtag;

            if (!string.Equals(clientEtag, serverEtag))
            {
                message["Content"] = context.Result;
            }

            await _outboundQueue.SendAsync(brokerProperties, message);
        }
示例#2
0
        private void DistpachMessage(object sender, MessageReceivedEventArgs e)
        {
            var apiRequest = e.Body.ToObject <ApiRequest>();

            var correlationId = (string)e.Body["CorrelationId"];

            var context   = new QueueBasedApiContext(correlationId, apiRequest.Action, apiRequest.Parameter, apiRequest.ResultHash);
            var eventArgs = new ApiRequestReceivedEventArgs(context);

            RequestReceived?.Invoke(this, eventArgs);

            if (!eventArgs.IsHandled)
            {
                context.ResultCode = ApiResultCode.ActionNotSupported;
            }

            SendResponseMessage(context).Wait();
        }