异步读取RequestBody

pull/22/head
Xuanye Wong 5 years ago
parent e2d82ae952
commit c5cbf8230f
  1. 2
      build/releasenotes.props
  2. 2
      build/version.props
  3. 3
      samples/ASPNetCoreExecutor/ASPNetCoreExecutor.csproj
  4. 4
      samples/ASPNetCoreExecutor/Extensions/XxlJobExecutorMiddleware.cs
  5. 9
      samples/ASPNetCoreExecutor/Startup.cs
  6. 6
      src/DotXxlJob.Core/XxlRestfulServiceHandler.cs

@ -1,7 +1,7 @@
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<DotXxlJobPackageNotes> <DotXxlJobPackageNotes>
1. 修改接口方式为Restful方式,适配xxl-jobv2.2以上版本 1. 修改异步方式读取RequestBody
</DotXxlJobPackageNotes> </DotXxlJobPackageNotes>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

@ -1,5 +1,5 @@
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<DotXxlJobPackageVersion>2.0.0</DotXxlJobPackageVersion> <DotXxlJobPackageVersion>2.0.2</DotXxlJobPackageVersion>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Extensions.Logging.Console"> <PackageReference Include="Microsoft.Extensions.Logging.Console">
<Version>2.2.0</Version> <Version>2.2.0</Version>
</PackageReference> </PackageReference>

@ -30,9 +30,9 @@ namespace ASPNetCoreExecutor
&& !string.IsNullOrEmpty(contentType) && !string.IsNullOrEmpty(contentType)
&& contentType.ToLower().StartsWith("application/json")) && contentType.ToLower().StartsWith("application/json"))
{ {
await _rpcService.HandlerAsync(context.Request,context.Response); await _rpcService.HandlerAsync(context.Request,context.Response);
return; return;
} }

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Server.Kestrel.Core;
namespace ASPNetCoreExecutor namespace ASPNetCoreExecutor
{ {
@ -27,12 +28,16 @@ namespace ASPNetCoreExecutor
services.AddSingleton<IJobHandler, DemoJobHandler>(); // 添加自定义的jobHandler services.AddSingleton<IJobHandler, DemoJobHandler>(); // 添加自定义的jobHandler
services.AddAutoRegistry(); // 自动注册 services.AddAutoRegistry(); // 自动注册
//services.Configure<KestrelServerOptions>(x => x.AllowSynchronousIO = true)
// .Configure<IISServerOptions>(x=> x.AllowSynchronousIO = true);
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // 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(); app.UseDeveloperExceptionPage();
} }

@ -65,7 +65,7 @@ namespace DotXxlJob.Core
} }
try try
{ {
string json = CollectBody(request.Body); string json = await CollectBody(request.Body);
switch (method) switch (method)
{ {
case "beat": case "beat":
@ -99,12 +99,12 @@ namespace DotXxlJob.Core
response.ContentType = "application/json;charset=utf-8"; response.ContentType = "application/json;charset=utf-8";
await response.WriteAsync(JsonConvert.SerializeObject(ret)); await response.WriteAsync(JsonConvert.SerializeObject(ret));
} }
private string CollectBody(Stream body) private async Task<string> CollectBody(Stream body)
{ {
string bodyText; string bodyText;
using (var reader = new StreamReader(body)) using (var reader = new StreamReader(body))
{ {
bodyText = reader.ReadToEnd(); bodyText = await reader.ReadToEndAsync();
} }
return bodyText; return bodyText;
} }

Loading…
Cancel
Save