From c5cbf8230fc83a4ecefcad94055c772b5880f87e Mon Sep 17 00:00:00 2001 From: Xuanye Wong Date: Mon, 11 Jan 2021 13:57:50 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E5=BC=82=E6=AD=A5=E8=AF=BB=E5=8F=96Req?= =?UTF-8?q?uestBody?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/releasenotes.props | 2 +- build/version.props | 2 +- samples/ASPNetCoreExecutor/ASPNetCoreExecutor.csproj | 3 +-- .../Extensions/XxlJobExecutorMiddleware.cs | 4 ++-- samples/ASPNetCoreExecutor/Startup.cs | 9 +++++++-- src/DotXxlJob.Core/XxlRestfulServiceHandler.cs | 6 +++--- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/build/releasenotes.props b/build/releasenotes.props index 01d3604..af40d41 100644 --- a/build/releasenotes.props +++ b/build/releasenotes.props @@ -1,7 +1,7 @@ - 1. 修改接口方式为Restful方式,适配xxl-jobv2.2以上版本 + 1. 修改异步方式读取RequestBody diff --git a/build/version.props b/build/version.props index c1ba8dc..3e06a3d 100644 --- a/build/version.props +++ b/build/version.props @@ -1,5 +1,5 @@ - 2.0.0 + 2.0.2 diff --git a/samples/ASPNetCoreExecutor/ASPNetCoreExecutor.csproj b/samples/ASPNetCoreExecutor/ASPNetCoreExecutor.csproj index 0562725..6f62e05 100644 --- a/samples/ASPNetCoreExecutor/ASPNetCoreExecutor.csproj +++ b/samples/ASPNetCoreExecutor/ASPNetCoreExecutor.csproj @@ -1,11 +1,10 @@  - netcoreapp2.2 + netcoreapp3.1 - 2.2.0 diff --git a/samples/ASPNetCoreExecutor/Extensions/XxlJobExecutorMiddleware.cs b/samples/ASPNetCoreExecutor/Extensions/XxlJobExecutorMiddleware.cs index dea4386..a02166b 100644 --- a/samples/ASPNetCoreExecutor/Extensions/XxlJobExecutorMiddleware.cs +++ b/samples/ASPNetCoreExecutor/Extensions/XxlJobExecutorMiddleware.cs @@ -30,9 +30,9 @@ namespace ASPNetCoreExecutor && !string.IsNullOrEmpty(contentType) && contentType.ToLower().StartsWith("application/json")) { - + await _rpcService.HandlerAsync(context.Request,context.Response); - + return; } diff --git a/samples/ASPNetCoreExecutor/Startup.cs b/samples/ASPNetCoreExecutor/Startup.cs index 1ae88f9..66735ee 100644 --- a/samples/ASPNetCoreExecutor/Startup.cs +++ b/samples/ASPNetCoreExecutor/Startup.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Server.Kestrel.Core; namespace ASPNetCoreExecutor { @@ -27,12 +28,16 @@ namespace ASPNetCoreExecutor services.AddSingleton(); // 添加自定义的jobHandler services.AddAutoRegistry(); // 自动注册 + + + //services.Configure(x => x.AllowSynchronousIO = true) + // .Configure(x=> x.AllowSynchronousIO = true); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app,IHostingEnvironment env) + public void Configure(IApplicationBuilder app,IWebHostEnvironment env) { - if (env.IsDevelopment()) + if (env.EnvironmentName !="Production") { app.UseDeveloperExceptionPage(); } diff --git a/src/DotXxlJob.Core/XxlRestfulServiceHandler.cs b/src/DotXxlJob.Core/XxlRestfulServiceHandler.cs index 4615549..a068c15 100644 --- a/src/DotXxlJob.Core/XxlRestfulServiceHandler.cs +++ b/src/DotXxlJob.Core/XxlRestfulServiceHandler.cs @@ -65,7 +65,7 @@ namespace DotXxlJob.Core } try { - string json = CollectBody(request.Body); + string json = await CollectBody(request.Body); switch (method) { case "beat": @@ -99,12 +99,12 @@ namespace DotXxlJob.Core response.ContentType = "application/json;charset=utf-8"; await response.WriteAsync(JsonConvert.SerializeObject(ret)); } - private string CollectBody(Stream body) + private async Task CollectBody(Stream body) { string bodyText; using (var reader = new StreamReader(body)) { - bodyText = reader.ReadToEnd(); + bodyText = await reader.ReadToEndAsync(); } return bodyText; }