public virtual async Task Handle(HttpContext context, ServiceEntry serviceEntry)
        {
            Check.NotNull(context, nameof(context));
            Check.NotNull(serviceEntry, nameof(serviceEntry));
            var requestParameters = await _parameterParser.Parser(context.Request, serviceEntry);

            RpcContext.GetContext().SetAttachment("requestHeader", requestParameters[ParameterFrom.Header]);
            var    rpcParameters = serviceEntry.ResolveParameters(requestParameters);
            string serviceKey    = null;

            if (context.Request.Headers.ContainsKey("serviceKey"))
            {
                serviceKey = context.Request.Headers["serviceKey"].ToString();
                RpcContext.GetContext().SetAttachment("serviceKey", serviceKey);
            }

            RpcContext.GetContext().SetAttachment("token", _rpcOptions.Token);
            var excuteResult = await _serviceExecutor.Execute(serviceEntry, rpcParameters, serviceKey);

            context.Response.ContentType = "application/json;charset=utf-8";
            context.Response.StatusCode  = 200;
            if (excuteResult != null)
            {
                var responseData = _serializer.Serialize(excuteResult);
                context.Response.ContentLength = responseData.GetBytes().Length;
                await context.Response.WriteAsync(responseData);
            }
            else
            {
                context.Response.ContentLength = 0;
                await context.Response.WriteAsync(string.Empty);
            }
        }
        public async Task <NoCommandResult> Handle(ProductListingCommand command)
        {
            this._logger.LogInformation($"Product listing Handler : {command.ProductCategory}");

            await _serviceExecutor.Execute <IProcessorA>(10);

            return(await Task.FromResult(NoCommandResult.Instance));
        }
Example #3
0
        private void _transporter_RequestReceived(object sender, RequestMessage reqMessage)
        {
            _logger.LogDebug("Received Request");
            ResponseMessage retMessage;

            try
            {
                object response = _executor.Execute(reqMessage);
                retMessage = ResponseMessage.ParseResult(_serviceInfo, reqMessage, response);
            }
            catch (Exception e)
            {
                retMessage = ResponseMessage.ParseError(_serviceInfo, reqMessage, e);
            }
            _logger.LogDebug($"Will return to MOL.RES.{reqMessage.Sender}");
            _logger.LogDebug(retMessage.ToString());
            _logger.LogDebug("End Will return");

            _transporter.Publish($"MOL.RES.{reqMessage.Sender}", retMessage);
        }
        public async override Task InterceptAsync(ILmsMethodInvocation invocation)
        {
            var servcieId    = _serviceIdGenerator.GenerateServiceId(invocation.Method);
            var serviceEntry = _serviceEntryLocator.GetServiceEntryById(servcieId);

            try
            {
                invocation.ReturnValue =
                    await _serviceExecutor.Execute(serviceEntry, invocation.Arguments, _currentServiceKey.ServiceKey);
            }
            catch (Exception e)
            {
                if (!e.IsBusinessException() && serviceEntry.FallBackExecutor != null)
                {
                    await invocation.ProceedAsync();
                }
                else
                {
                    throw;
                }
            }
        }