Skip to content

Commit

Permalink
升级到.net core 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
oujun committed Oct 7, 2019
1 parent c347f49 commit 0d153ec
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 31 deletions.
22 changes: 9 additions & 13 deletions RabbitMQ.EventBus.AspNetCore.Simple/Program.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace RabbitMQ.EventBus.AspNetCore.Simple
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
CreateHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
</PropertyGroup>

<ItemGroup>
Expand Down
22 changes: 19 additions & 3 deletions RabbitMQ.EventBus.AspNetCore.Simple/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using System;
using System.Reflection;

Expand All @@ -21,9 +23,11 @@ public Startup(IConfiguration configuration)
public void ConfigureServices(IServiceCollection services)
{
string assemblyName = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

services.AddRabbitMQEventBus(() => "amqp://guest:guest@192.168.0.251:5672/", eventBusOptionAction: eventBusOption =>
services.AddControllers();
services.AddHealthChecks();

services.AddRabbitMQEventBus(() => "amqp://guest:guest@192.168.0.250:5672/", eventBusOptionAction: eventBusOption =>
{
eventBusOption.ClientProvidedAssembly(assemblyName);
eventBusOption.EnableRetryOnFailure(true, 5000, TimeSpan.FromSeconds(30));
Expand All @@ -38,8 +42,20 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.RabbitMQEventBusAutoSubscribe();
app.UseMvc();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHealthChecks("/hc", new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions
{
ResultStatusCodes = {
[HealthStatus.Healthy] = StatusCodes.Status200OK,
[HealthStatus.Degraded] = StatusCodes.Status200OK,
[HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable
}
});
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using RabbitMQ.EventBus.AspNetCore.Attributes;
Expand Down
13 changes: 11 additions & 2 deletions src/RabbitMQ.EventBus.AspNetCore/Events/EventHandlerArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.ComponentModel;
using System.Text.Json;

namespace RabbitMQ.EventBus.AspNetCore.Events
{
Expand Down Expand Up @@ -47,7 +48,15 @@ public TEvent Event
{
if (_event == null)
{
_event = JsonConvert.DeserializeObject<TEvent>(Original);
try
{

_event = JsonSerializer.Deserialize<TEvent>(Original);
}
catch
{
_event = (TEvent)TypeDescriptor.GetConverter(typeof(TEvent)).ConvertFromInvariantString(Original);
}
}
return _event;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Newtonsoft.Json;
using System.Text;
using System.Text;
using System.Text.Json;

namespace System
{
Expand All @@ -16,7 +16,7 @@ public static class DynamicExtensions
/// <returns></returns>
public static string Serialize<TMessage>(this TMessage message)
{
return JsonConvert.SerializeObject(message);
return JsonSerializer.Serialize(message);
}
/// <summary>
///
Expand Down
1 change: 0 additions & 1 deletion src/RabbitMQ.EventBus.AspNetCore/IRabbitMQEventBus.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using RabbitMQ.Client;
using RabbitMQ.EventBus.AspNetCore.Events;
using System;

namespace RabbitMQ.EventBus.AspNetCore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageIconUrl></PackageIconUrl>
<RepositoryUrl>https://github.com/ojdev/RabbitMQ.EventBus.AspNetCore</RepositoryUrl>
Expand All @@ -22,11 +22,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Polly" Version="7.1.0" />
<PackageReference Include="RabbitMQ.Client" Version="5.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.0.0" />
<PackageReference Include="Polly" Version="7.1.1" />
<PackageReference Include="RabbitMQ.Client" Version="5.1.1" />
<PackageReference Include="System.Text.Json" Version="4.6.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 0d153ec

Please sign in to comment.