Skip to content

Commit d0be90e

Browse files
authored
Merge pull request #48 from ojdev/dev
升级到.net 5.0
2 parents 2ac0820 + d9f2761 commit d0be90e

7 files changed

Lines changed: 22 additions & 35 deletions

File tree

.github/workflows/dotnetcore.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
- name: Setup .NET Core
1616
uses: actions/setup-dotnet@v1
1717
with:
18-
dotnet-version: 3.1.100
18+
dotnet-version: 5.0.301
1919
- name: Build with dotnet
2020
run: dotnet build --configuration Release src/RabbitMQ.EventBus.AspNetCore
2121
- name: Pack
22-
run: dotnet pack src/RabbitMQ.EventBus.AspNetCore -c Release --include-symbols --include-source -p:PackageVersion=3.1.$GITHUB_RUN_NUMBER -o artifacts/
22+
run: dotnet pack src/RabbitMQ.EventBus.AspNetCore -c Release --include-symbols --include-source -p:PackageVersion=5.0.$GITHUB_RUN_NUMBER -o artifacts/
2323
- name: Publish Symbols to NuGet
2424
run: dotnet nuget push artifacts/*.symbols.nupkg --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json

RabbitMQ.EventBus.AspNetCore.Sample/RabbitMQ.EventBus.AspNetCore.Sample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
66
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
77
</PropertyGroup>

src/RabbitMQ.EventBus.AspNetCore/DefaultRabbitMQEventBus.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void Publish<TMessage>(TMessage message, string exchange, string routingK
6666
mandatory: true,
6767
basicProperties: properties,
6868
body: body.GetBytes());
69-
_logger.WriteLog(_persistentConnection.Configuration.Level, $"{DateTimeOffset.Now.ToString("yyyy-MM-dd HH:mm:ss")}\t{exchange}\t{routingKey}\t{body}");
69+
_logger.WriteLog(_persistentConnection.Configuration.Level, $"{DateTimeOffset.Now:yyyy-MM-dd HH:mm:ss}\t{exchange}\t{routingKey}\t{body}");
7070
_eventHandlerFactory?.PubliushEvent(new EventBusArgs(_persistentConnection.Endpoint, exchange, "", routingKey, type, _persistentConnection.Configuration.ClientProvidedName, body, true));
7171
}
7272
public void Subscribe(Type eventType, string type = ExchangeType.Topic)
@@ -134,7 +134,7 @@ public void Subscribe(Type eventType, string type = ExchangeType.Topic)
134134
#endregion
135135
channel.QueueBind(queue, attr.Exchange, attr.RoutingKey, null);
136136
channel.BasicQos(0, _persistentConnection.Configuration.PrefetchCount, false);
137-
EventingBasicConsumer consumer = new EventingBasicConsumer(channel);
137+
EventingBasicConsumer consumer = new(channel);
138138
consumer.Received += async (model, ea) =>
139139
{
140140
string body = Encoding.UTF8.GetString(ea.Body.ToArray());
@@ -153,7 +153,7 @@ public void Subscribe(Type eventType, string type = ExchangeType.Topic)
153153
finally
154154
{
155155
_eventHandlerFactory?.SubscribeEvent(new EventBusArgs(_persistentConnection.Endpoint, ea.Exchange, queue, attr.RoutingKey, type, _persistentConnection.Configuration.ClientProvidedName, body, isAck));
156-
_logger.WriteLog(_persistentConnection.Configuration.Level, $"{DateTimeOffset.Now.ToString("yyyy-MM-dd HH:mm:ss")}\t{isAck}\t{ea.Exchange}\t{ea.RoutingKey}\t{body}");
156+
_logger.WriteLog(_persistentConnection.Configuration.Level, $"{DateTimeOffset.Now:yyyy-MM-dd HH:mm:ss}\t{isAck}\t{ea.Exchange}\t{ea.RoutingKey}\t{body}");
157157
if (!isAck)
158158
{
159159
await Task.Delay(millisecondsDelay);

src/RabbitMQ.EventBus.AspNetCore/Events/EventHandlerArgs.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using Microsoft.Extensions.Logging;
2+
using Newtonsoft.Json;
23
using System;
34
using System.ComponentModel;
4-
using System.Text.Encodings.Web;
5-
using System.Text.Json;
6-
using System.Text.Unicode;
75

86
namespace RabbitMQ.EventBus.AspNetCore.Events
97
{
@@ -57,11 +55,7 @@ public TEvent Event
5755
{
5856
try
5957
{
60-
_event = JsonSerializer.Deserialize<TEvent>(Original, new JsonSerializerOptions
61-
{
62-
PropertyNameCaseInsensitive = true,
63-
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
64-
});
58+
_event = JsonConvert.DeserializeObject<TEvent>(Original);
6559
}
6660
catch
6761
{
@@ -72,7 +66,7 @@ public TEvent Event
7266
catch (Exception ex)
7367
{
7468
_logger.LogError(new EventId(ex.HResult), ex, $"content {Original} deserialize type {typeof(TEvent).Name} error {ex.Message}");
75-
throw ex;
69+
throw;
7670
}
7771
}
7872
}

src/RabbitMQ.EventBus.AspNetCore/Extensions/DynamicExtensions.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System.Text;
2-
using System.Text.Encodings.Web;
3-
using System.Text.Json;
4-
using System.Text.Unicode;
1+
using Newtonsoft.Json;
2+
using System.Text;
53

64
namespace System
75
{
@@ -18,11 +16,7 @@ internal static class DynamicExtensions
1816
/// <returns></returns>
1917
public static string Serialize<TMessage>(this TMessage message)
2018
{
21-
return JsonSerializer.Serialize(message, new JsonSerializerOptions
22-
{
23-
PropertyNameCaseInsensitive = true,
24-
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
25-
});
19+
return JsonConvert.SerializeObject(message);
2620
}
2721
/// <summary>
2822
///

src/RabbitMQ.EventBus.AspNetCore/Extensions/ServiceCollectionExtensions.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Microsoft.AspNetCore.Builder;
22
using Microsoft.Extensions.DependencyInjection.Extensions;
33
using Microsoft.Extensions.Logging;
4-
using RabbitMQ.Client;
54
using RabbitMQ.EventBus.AspNetCore;
65
using RabbitMQ.EventBus.AspNetCore.Configurations;
76
using RabbitMQ.EventBus.AspNetCore.Events;
@@ -26,8 +25,8 @@ public static class ServiceCollectionExtensions
2625
/// <returns></returns>
2726
public static IServiceCollection AddRabbitMQEventBus(this IServiceCollection services, Func<string> connectionAction, Action<RabbitMQEventBusConnectionConfigurationBuild> eventBusOptionAction)
2827
{
29-
RabbitMQEventBusConnectionConfiguration configuration = new RabbitMQEventBusConnectionConfiguration();
30-
RabbitMQEventBusConnectionConfigurationBuild configurationBuild = new RabbitMQEventBusConnectionConfigurationBuild(configuration);
28+
RabbitMQEventBusConnectionConfiguration configuration = new();
29+
RabbitMQEventBusConnectionConfigurationBuild configurationBuild = new(configuration);
3130
eventBusOptionAction?.Invoke(configurationBuild);
3231
services.TryAddSingleton<IRabbitMQPersistentConnection>(options =>
3332
{
@@ -79,7 +78,7 @@ public static void RabbitMQEventBusAutoSubscribe(this IApplicationBuilder app)
7978
public static void RabbitMQEventBusModule(this IApplicationBuilder app, Action<RabbitMQEventBusModuleOption> moduleOptions)
8079
{
8180
IEventHandlerModuleFactory factory = app.ApplicationServices.GetRequiredService<IEventHandlerModuleFactory>();
82-
RabbitMQEventBusModuleOption moduleOption = new RabbitMQEventBusModuleOption(factory, app.ApplicationServices);
81+
RabbitMQEventBusModuleOption moduleOption = new(factory, app.ApplicationServices);
8382
moduleOptions?.Invoke(moduleOption);
8483
}
8584
}

src/RabbitMQ.EventBus.AspNetCore/RabbitMQ.EventBus.AspNetCore.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
66
<PackageIconUrl></PackageIconUrl>
77
<RepositoryUrl>https://github.com/ojdev/RabbitMQ.EventBus.AspNetCore</RepositoryUrl>
@@ -12,7 +12,7 @@
1212
<Description>asp.net core 下使用的RabbitMQ</Description>
1313
<PackageLicenseUrl></PackageLicenseUrl>
1414
<PackageProjectUrl>https://github.com/ojdev/RabbitMQ.EventBus.AspNetCore</PackageProjectUrl>
15-
<Version>2.1.4</Version>
15+
<Version>5.0.1</Version>
1616
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1717
</PropertyGroup>
1818

@@ -22,11 +22,11 @@
2222

2323
<ItemGroup>
2424
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
25-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.5" />
26-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.5" />
27-
<PackageReference Include="Polly" Version="7.2.1" />
28-
<PackageReference Include="RabbitMQ.Client" Version="6.1.0" />
29-
<PackageReference Include="System.Text.Json" Version="4.7.2" />
25+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
26+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
27+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
28+
<PackageReference Include="Polly" Version="7.2.2" />
29+
<PackageReference Include="RabbitMQ.Client" Version="6.2.1" />
3030
</ItemGroup>
3131

3232
<ItemGroup>

0 commit comments

Comments
 (0)