コード例 #1
0
        public async Task Handle(IOwinContext owinContext, Func <Task> next)
        {
            if (_stopping)
            {
                owinContext.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
                owinContext.Response.Write("Stopping");

                await next().ConfigureAwait(false);

                return;
            }

            using (_tracker.BeginDelivery())
            {
                var responseProxy = new HttpResponseSendEndpointProvider(_receiveSettings, owinContext, _inputAddress, _sendPipe);

                var context = new HttpReceiveContext(owinContext, false, _receiveObserver, responseProxy, _receiveSettings.PublishEndpointProvider);

                try
                {
                    await _receiveObserver.PreReceive(context).ConfigureAwait(false);

                    await _receivePipe.Send(context).ConfigureAwait(false);

                    await context.CompleteTask.ConfigureAwait(false);

                    //TODO: Push into Pipe! -- cant' be on the receive pipe because it doesn't have the content
                    if (!owinContext.Response.ContentLength.HasValue)
                    {
                        owinContext.Response.StatusCode = (int)HttpStatusCode.Accepted;
                        owinContext.Response.Write("");
                    }

                    await next().ConfigureAwait(false);

                    await _receiveObserver.PostReceive(context).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    await _receiveObserver.ReceiveFault(context, ex).ConfigureAwait(false);

                    //TODO: Push into pipe?
                    owinContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                }
                finally
                {
                    context.Dispose();
                }
            }
        }
コード例 #2
0
ファイル: HttpConsumer.cs プロジェクト: youqingz/MassTransit
        public async Task Handle(HttpContext httpContext, Func <Task> next)
        {
            if (IsStopping)
            {
                httpContext.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
                await httpContext.Response.WriteAsync("Stopping").ConfigureAwait(false);

                await next().ConfigureAwait(false);

                return;
            }

            using (_tracker.BeginDelivery())
            {
                var responseEndpointContext = _context.CreateResponseEndpointContext(httpContext);

                var context = new HttpReceiveContext(httpContext, false, responseEndpointContext);

                try
                {
                    await _context.ReceiveObservers.PreReceive(context).ConfigureAwait(false);

                    await _context.ReceivePipe.Send(context).ConfigureAwait(false);

                    await context.ReceiveCompleted.ConfigureAwait(false);

                    //TODO: Push into Pipe! -- can't be on the receive pipe because it doesn't have the content
                    if (!httpContext.Response.ContentLength.HasValue)
                    {
                        httpContext.Response.StatusCode = (int)HttpStatusCode.Accepted;
                    }

                    await _context.ReceiveObservers.PostReceive(context).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    await _context.ReceiveObservers.ReceiveFault(context, ex).ConfigureAwait(false);

                    //TODO: ensure the Fault is written to the response pipe
                    httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                }
                finally
                {
                    context.Dispose();
                }
            }
        }
コード例 #3
0
        public async Task Handle(IOwinContext owinContext, Func<Task> next)
        {
            if (_stopping)
            {
                owinContext.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
                owinContext.Response.Write("Stopping");

                await next().ConfigureAwait(false);

                return;
            }

            using (_tracker.BeginDelivery())
            {

                var responseProxy = new HttpResponseSendEndpointProvider(_receiveSettings, owinContext, _inputAddress, _sendPipe);

                var context = new HttpReceiveContext(owinContext, false, _receiveObserver, responseProxy, _receiveSettings.PublishEndpointProvider);

                try
                {
                    await _receiveObserver.PreReceive(context).ConfigureAwait(false);

                    await _receivePipe.Send(context).ConfigureAwait(false);

                    await context.CompleteTask.ConfigureAwait(false);

                    //TODO: Push into Pipe! -- cant' be on the receive pipe because it doesn't have the content
                    if (!owinContext.Response.ContentLength.HasValue)
                    {
                        owinContext.Response.StatusCode = (int)HttpStatusCode.Accepted;
                        owinContext.Response.Write("");
                    }

                    await next().ConfigureAwait(false);

                    await _receiveObserver.PostReceive(context).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    await _receiveObserver.ReceiveFault(context, ex).ConfigureAwait(false);

                    //TODO: Push into pipe?
                    owinContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                }
                finally
                {
                    context.Dispose();
                }
            }
        }