Skip to content

Commit

Permalink
Merge pull request #48 from ojdev/dev
Browse files Browse the repository at this point in the history
升级到.net 5.0
  • Loading branch information
ojdev committed Jun 9, 2021
2 parents 2ac0820 + d9f2761 commit d0be90e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dotnetcore.yml
Expand Up @@ -15,10 +15,10 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.100
dotnet-version: 5.0.301
- name: Build with dotnet
run: dotnet build --configuration Release src/RabbitMQ.EventBus.AspNetCore
- name: Pack
run: dotnet pack src/RabbitMQ.EventBus.AspNetCore -c Release --include-symbols --include-source -p:PackageVersion=3.1.$GITHUB_RUN_NUMBER -o artifacts/
run: dotnet pack src/RabbitMQ.EventBus.AspNetCore -c Release --include-symbols --include-source -p:PackageVersion=5.0.$GITHUB_RUN_NUMBER -o artifacts/
- name: Publish Symbols to NuGet
run: dotnet nuget push artifacts/*.symbols.nupkg --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/RabbitMQ.EventBus.AspNetCore/DefaultRabbitMQEventBus.cs
Expand Up @@ -66,7 +66,7 @@ public void Publish<TMessage>(TMessage message, string exchange, string routingK
mandatory: true,
basicProperties: properties,
body: body.GetBytes());
_logger.WriteLog(_persistentConnection.Configuration.Level, $"{DateTimeOffset.Now.ToString("yyyy-MM-dd HH:mm:ss")}\t{exchange}\t{routingKey}\t{body}");
_logger.WriteLog(_persistentConnection.Configuration.Level, $"{DateTimeOffset.Now:yyyy-MM-dd HH:mm:ss}\t{exchange}\t{routingKey}\t{body}");
_eventHandlerFactory?.PubliushEvent(new EventBusArgs(_persistentConnection.Endpoint, exchange, "", routingKey, type, _persistentConnection.Configuration.ClientProvidedName, body, true));
}
public void Subscribe(Type eventType, string type = ExchangeType.Topic)
Expand Down Expand Up @@ -134,7 +134,7 @@ public void Subscribe(Type eventType, string type = ExchangeType.Topic)
#endregion
channel.QueueBind(queue, attr.Exchange, attr.RoutingKey, null);
channel.BasicQos(0, _persistentConnection.Configuration.PrefetchCount, false);
EventingBasicConsumer consumer = new EventingBasicConsumer(channel);
EventingBasicConsumer consumer = new(channel);
consumer.Received += async (model, ea) =>
{
string body = Encoding.UTF8.GetString(ea.Body.ToArray());
Expand All @@ -153,7 +153,7 @@ public void Subscribe(Type eventType, string type = ExchangeType.Topic)
finally
{
_eventHandlerFactory?.SubscribeEvent(new EventBusArgs(_persistentConnection.Endpoint, ea.Exchange, queue, attr.RoutingKey, type, _persistentConnection.Configuration.ClientProvidedName, body, isAck));
_logger.WriteLog(_persistentConnection.Configuration.Level, $"{DateTimeOffset.Now.ToString("yyyy-MM-dd HH:mm:ss")}\t{isAck}\t{ea.Exchange}\t{ea.RoutingKey}\t{body}");
_logger.WriteLog(_persistentConnection.Configuration.Level, $"{DateTimeOffset.Now:yyyy-MM-dd HH:mm:ss}\t{isAck}\t{ea.Exchange}\t{ea.RoutingKey}\t{body}");
if (!isAck)
{
await Task.Delay(millisecondsDelay);
Expand Down
12 changes: 3 additions & 9 deletions src/RabbitMQ.EventBus.AspNetCore/Events/EventHandlerArgs.cs
@@ -1,9 +1,7 @@
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.ComponentModel;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Unicode;

namespace RabbitMQ.EventBus.AspNetCore.Events
{
Expand Down Expand Up @@ -57,11 +55,7 @@ public TEvent Event
{
try
{
_event = JsonSerializer.Deserialize<TEvent>(Original, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
});
_event = JsonConvert.DeserializeObject<TEvent>(Original);
}
catch
{
Expand All @@ -72,7 +66,7 @@ public TEvent Event
catch (Exception ex)
{
_logger.LogError(new EventId(ex.HResult), ex, $"content {Original} deserialize type {typeof(TEvent).Name} error {ex.Message}");
throw ex;
throw;
}
}
}
Expand Down
12 changes: 3 additions & 9 deletions src/RabbitMQ.EventBus.AspNetCore/Extensions/DynamicExtensions.cs
@@ -1,7 +1,5 @@
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Unicode;
using Newtonsoft.Json;
using System.Text;

namespace System
{
Expand All @@ -18,11 +16,7 @@ internal static class DynamicExtensions
/// <returns></returns>
public static string Serialize<TMessage>(this TMessage message)
{
return JsonSerializer.Serialize(message, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
});
return JsonConvert.SerializeObject(message);
}
/// <summary>
///
Expand Down
@@ -1,7 +1,6 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using RabbitMQ.Client;
using RabbitMQ.EventBus.AspNetCore;
using RabbitMQ.EventBus.AspNetCore.Configurations;
using RabbitMQ.EventBus.AspNetCore.Events;
Expand All @@ -26,8 +25,8 @@ public static class ServiceCollectionExtensions
/// <returns></returns>
public static IServiceCollection AddRabbitMQEventBus(this IServiceCollection services, Func<string> connectionAction, Action<RabbitMQEventBusConnectionConfigurationBuild> eventBusOptionAction)
{
RabbitMQEventBusConnectionConfiguration configuration = new RabbitMQEventBusConnectionConfiguration();
RabbitMQEventBusConnectionConfigurationBuild configurationBuild = new RabbitMQEventBusConnectionConfigurationBuild(configuration);
RabbitMQEventBusConnectionConfiguration configuration = new();
RabbitMQEventBusConnectionConfigurationBuild configurationBuild = new(configuration);
eventBusOptionAction?.Invoke(configurationBuild);
services.TryAddSingleton<IRabbitMQPersistentConnection>(options =>
{
Expand Down Expand Up @@ -79,7 +78,7 @@ public static void RabbitMQEventBusAutoSubscribe(this IApplicationBuilder app)
public static void RabbitMQEventBusModule(this IApplicationBuilder app, Action<RabbitMQEventBusModuleOption> moduleOptions)
{
IEventHandlerModuleFactory factory = app.ApplicationServices.GetRequiredService<IEventHandlerModuleFactory>();
RabbitMQEventBusModuleOption moduleOption = new RabbitMQEventBusModuleOption(factory, app.ApplicationServices);
RabbitMQEventBusModuleOption moduleOption = new(factory, app.ApplicationServices);
moduleOptions?.Invoke(moduleOption);
}
}
Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageIconUrl></PackageIconUrl>
<RepositoryUrl>https://github.com/ojdev/RabbitMQ.EventBus.AspNetCore</RepositoryUrl>
Expand All @@ -12,7 +12,7 @@
<Description>asp.net core 下使用的RabbitMQ</Description>
<PackageLicenseUrl></PackageLicenseUrl>
<PackageProjectUrl>https://github.com/ojdev/RabbitMQ.EventBus.AspNetCore</PackageProjectUrl>
<Version>2.1.4</Version>
<Version>5.0.1</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>

Expand All @@ -22,11 +22,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.5" />
<PackageReference Include="Polly" Version="7.2.1" />
<PackageReference Include="RabbitMQ.Client" Version="6.1.0" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Polly" Version="7.2.2" />
<PackageReference Include="RabbitMQ.Client" Version="6.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit d0be90e

Please sign in to comment.