diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9e3efa6..22cb8ce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - dotnet-version: [ '6.0' ] + dotnet-version: [ '9.0' ] steps: - uses: actions/checkout@v3 @@ -29,7 +29,7 @@ jobs: - name: Test run: dotnet test . --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}" - name: Upload test results - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: dotnet-results-${{ matrix.dotnet-version }} path: TestResults-${{ matrix.dotnet-version }} diff --git a/.github/workflows/deploy-nuget.yml b/.github/workflows/deploy-nuget.yml index b8ed830..9c417bd 100644 --- a/.github/workflows/deploy-nuget.yml +++ b/.github/workflows/deploy-nuget.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-dotnet@v2 with: - dotnet-version: '6.0.x' + dotnet-version: '9.0.x' - run: dotnet build --configuration Release . - name: Create the packages run: | diff --git a/Jamq.Client.sln b/Jamq.Client.sln index 77aa8d1..2486aea 100644 --- a/Jamq.Client.sln +++ b/Jamq.Client.sln @@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution-items", "solution- ProjectSection(SolutionItems) = preProject src\Directory.Build.props = src\Directory.Build.props README.md = README.md + src\Directory.Packages.props = src\Directory.Packages.props EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{042A1773-4B2B-4D52-A296-9A116CA2594C}" diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 1d12c35..7f0aba4 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -3,8 +3,10 @@ quilin quilin RabbitMQ, Kafka, Client + 10 https://github.com/quilin/Jamq.Client https://github.com/quilin/Jamq.Client + true diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props new file mode 100644 index 0000000..a232003 --- /dev/null +++ b/src/Directory.Packages.props @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Jamq.Client.Abstractions/Consuming/IsExternalInit.cs b/src/Jamq.Client.Abstractions/Consuming/IsExternalInit.cs new file mode 100644 index 0000000..499252a --- /dev/null +++ b/src/Jamq.Client.Abstractions/Consuming/IsExternalInit.cs @@ -0,0 +1,3 @@ +namespace System.Runtime.CompilerServices; + +internal static class IsExternalInit {} \ No newline at end of file diff --git a/src/Jamq.Client.Abstractions/Jamq.Client.Abstractions.csproj b/src/Jamq.Client.Abstractions/Jamq.Client.Abstractions.csproj index d572c8a..b7e843a 100644 --- a/src/Jamq.Client.Abstractions/Jamq.Client.Abstractions.csproj +++ b/src/Jamq.Client.Abstractions/Jamq.Client.Abstractions.csproj @@ -1,14 +1,15 @@ - net6.0 + netstandard2.1 enable enable true - + + diff --git a/src/Jamq.Client.DependencyInjection/Jamq.Client.DependencyInjection.csproj b/src/Jamq.Client.DependencyInjection/Jamq.Client.DependencyInjection.csproj index dd6deb0..4840191 100644 --- a/src/Jamq.Client.DependencyInjection/Jamq.Client.DependencyInjection.csproj +++ b/src/Jamq.Client.DependencyInjection/Jamq.Client.DependencyInjection.csproj @@ -1,14 +1,14 @@ - net6.0 + netstandard2.1 enable enable true - + diff --git a/src/Jamq.Client.Kafka.DependencyInjection/Jamq.Client.Kafka.DependencyInjection.csproj b/src/Jamq.Client.Kafka.DependencyInjection/Jamq.Client.Kafka.DependencyInjection.csproj index 370e545..e0309e4 100644 --- a/src/Jamq.Client.Kafka.DependencyInjection/Jamq.Client.Kafka.DependencyInjection.csproj +++ b/src/Jamq.Client.Kafka.DependencyInjection/Jamq.Client.Kafka.DependencyInjection.csproj @@ -1,7 +1,7 @@ - net6.0 + netstandard2.1 enable enable true diff --git a/src/Jamq.Client.Kafka/Jamq.Client.Kafka.csproj b/src/Jamq.Client.Kafka/Jamq.Client.Kafka.csproj index 8c6a848..1d2d55d 100644 --- a/src/Jamq.Client.Kafka/Jamq.Client.Kafka.csproj +++ b/src/Jamq.Client.Kafka/Jamq.Client.Kafka.csproj @@ -1,7 +1,7 @@ - net6.0 + netstandard2.1 enable enable true @@ -14,8 +14,9 @@ - - + + + diff --git a/src/Jamq.Client.OpenTelemetry/Jamq.Client.OpenTelemetry.csproj b/src/Jamq.Client.OpenTelemetry/Jamq.Client.OpenTelemetry.csproj index 80b4a88..23121d4 100644 --- a/src/Jamq.Client.OpenTelemetry/Jamq.Client.OpenTelemetry.csproj +++ b/src/Jamq.Client.OpenTelemetry/Jamq.Client.OpenTelemetry.csproj @@ -1,14 +1,14 @@ - net6.0 + netstandard2.1 enable enable true - + diff --git a/src/Jamq.Client.Rabbit.DependencyInjection/Jamq.Client.Rabbit.DependencyInjection.csproj b/src/Jamq.Client.Rabbit.DependencyInjection/Jamq.Client.Rabbit.DependencyInjection.csproj index 2b25588..527d9f4 100644 --- a/src/Jamq.Client.Rabbit.DependencyInjection/Jamq.Client.Rabbit.DependencyInjection.csproj +++ b/src/Jamq.Client.Rabbit.DependencyInjection/Jamq.Client.Rabbit.DependencyInjection.csproj @@ -1,7 +1,7 @@ - net6.0 + netstandard2.1 enable enable true diff --git a/src/Jamq.Client.Rabbit/Ensure.cs b/src/Jamq.Client.Rabbit/Ensure.cs index ee3f100..b6f1f1e 100644 --- a/src/Jamq.Client.Rabbit/Ensure.cs +++ b/src/Jamq.Client.Rabbit/Ensure.cs @@ -1,7 +1,6 @@ using Jamq.Client.Rabbit.Consuming; using Jamq.Client.Rabbit.Producing; using RabbitMQ.Client; -using System.Collections.Immutable; namespace Jamq.Client.Rabbit; @@ -23,11 +22,11 @@ public static QueueDeclareOk Consume(IModel channel, RabbitConsumerParameters pa exchange: parameters.ExchangeName, type: parameters.ExchangeType.ToString().ToLower(), durable: true, - arguments: parameters.AdditionalExchangeArguments ?? ImmutableDictionary.Empty); + arguments: parameters.AdditionalExchangeArguments ?? new Dictionary()); } var queueArguments = new Dictionary( - parameters.AdditionalQueueArguments ?? ImmutableDictionary.Empty); + parameters.AdditionalQueueArguments ?? new Dictionary()); var queueName = parameters.Exclusive ? parameters.QueueName.WithRandomSuffix() diff --git a/src/Jamq.Client.Rabbit/Jamq.Client.Rabbit.csproj b/src/Jamq.Client.Rabbit/Jamq.Client.Rabbit.csproj index a8d8d3d..0d04686 100644 --- a/src/Jamq.Client.Rabbit/Jamq.Client.Rabbit.csproj +++ b/src/Jamq.Client.Rabbit/Jamq.Client.Rabbit.csproj @@ -1,16 +1,17 @@ - net6.0 + netstandard2.1 enable enable true - - - + + + + diff --git a/src/Jamq.Client.Tests/Jamq.Client.Tests.csproj b/src/Jamq.Client.Tests/Jamq.Client.Tests.csproj index 524c326..8a3e401 100644 --- a/src/Jamq.Client.Tests/Jamq.Client.Tests.csproj +++ b/src/Jamq.Client.Tests/Jamq.Client.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + net9.0 enable enable @@ -11,17 +11,17 @@ - - - - - - - + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/Jamq.Client.Tests/Rabbit/RabbitConsumerBuilderShould.cs b/src/Jamq.Client.Tests/Rabbit/RabbitConsumerBuilderShould.cs index e96b048..1765b7d 100644 --- a/src/Jamq.Client.Tests/Rabbit/RabbitConsumerBuilderShould.cs +++ b/src/Jamq.Client.Tests/Rabbit/RabbitConsumerBuilderShould.cs @@ -7,7 +7,6 @@ using Jamq.Client.Rabbit.Producing; using Microsoft.Extensions.DependencyInjection; using Moq; -using Xunit.Abstractions; namespace Jamq.Client.Tests.Rabbit; @@ -17,8 +16,7 @@ public class RabbitConsumerBuilderShould : IClassFixture private readonly Mock caller; public RabbitConsumerBuilderShould( - RabbitFixture fixture, - ITestOutputHelper testOutputHelper) + RabbitFixture fixture) { this.fixture = fixture; caller = new Mock(); @@ -27,14 +25,11 @@ public RabbitConsumerBuilderShould( fixture.ServiceCollection.AddScoped(); fixture.ServiceCollection.AddScoped(); - DiagnosticListener.AllListeners.Subscribe(new RabbitFixture.Subscriber(testOutputHelper)); ActivitySource.AddActivityListener(new ActivityListener { ShouldListenTo = s => s.Name == Event.SourceName, SampleUsingParentId = (ref ActivityCreationOptions _) => ActivitySamplingResult.AllData, Sample = (ref ActivityCreationOptions _) => ActivitySamplingResult.AllData, - ActivityStarted = activity => testOutputHelper.WriteLine($"Activity {activity.DisplayName}:{activity.Id} started at {activity.StartTimeUtc:O}"), - ActivityStopped = activity => testOutputHelper.WriteLine($"Activity {activity.DisplayName}:{activity.Id} stopped at {activity.StartTimeUtc + activity.Duration:O} (after {activity.Duration:g})"), }); } diff --git a/src/Jamq.Client.Tests/Rabbit/RabbitFixture.cs b/src/Jamq.Client.Tests/Rabbit/RabbitFixture.cs index 4f0405a..aedf7e4 100644 --- a/src/Jamq.Client.Tests/Rabbit/RabbitFixture.cs +++ b/src/Jamq.Client.Tests/Rabbit/RabbitFixture.cs @@ -1,6 +1,4 @@ -using System.Diagnostics; -using Jamq.Client.Abstractions.Consuming; -using Jamq.Client.Abstractions.Diagnostics; +using Jamq.Client.Abstractions.Consuming; using Jamq.Client.Abstractions.Producing; using Jamq.Client.DependencyInjection; using Jamq.Client.Rabbit; @@ -9,7 +7,6 @@ using Moq; using RabbitMQ.Client; using RabbitMQ.Client.Events; -using Xunit.Abstractions; namespace Jamq.Client.Tests.Rabbit; @@ -82,50 +79,4 @@ public RabbitFixture() public void Dispose() { } - - internal class Subscriber : IObserver - { - private readonly ITestOutputHelper testOutputHelper; - - public Subscriber(ITestOutputHelper testOutputHelper) - { - this.testOutputHelper = testOutputHelper; - } - - public void OnCompleted() - { - } - - public void OnError(Exception error) - { - } - - public void OnNext(DiagnosticListener value) - { - if (value.Name == Event.SourceName) - { - value.Subscribe(new Listener(testOutputHelper)); - } - } - } - - private class Listener : IObserver> - { - private readonly ITestOutputHelper testOutputHelper; - - public Listener(ITestOutputHelper testOutputHelper) - { - this.testOutputHelper = testOutputHelper; - } - - public void OnCompleted() - { - } - - public void OnError(Exception error) - { - } - - public void OnNext(KeyValuePair keyValue) => testOutputHelper.WriteLine($"{keyValue.Key} - {keyValue.Value}"); - } } \ No newline at end of file diff --git a/src/Jamq.Client/Consuming/ConsumerBuilder.cs b/src/Jamq.Client/Consuming/ConsumerBuilder.cs index cd0342b..f5c75a9 100644 --- a/src/Jamq.Client/Consuming/ConsumerBuilder.cs +++ b/src/Jamq.Client/Consuming/ConsumerBuilder.cs @@ -143,7 +143,7 @@ public IConsumerBuilder Flush() var parameters = methodInfo.GetParameters(); if (parameters.Length < 2 || - !parameters.First().ParameterType.IsAssignableTo(typeof(ConsumerContext)) || + !typeof(ConsumerContext).IsAssignableFrom(parameters[0].ParameterType) || parameters.Last().ParameterType != typeof(CancellationToken)) { throw ConsumerBuilderMiddlewareConventionException.MismatchParameters(type); diff --git a/src/Jamq.Client/Jamq.Client.csproj b/src/Jamq.Client/Jamq.Client.csproj index 07cf512..ba805b9 100644 --- a/src/Jamq.Client/Jamq.Client.csproj +++ b/src/Jamq.Client/Jamq.Client.csproj @@ -1,14 +1,14 @@ - net6.0 + netstandard2.1 enable enable true - + diff --git a/src/Jamq.Client/MethodInfoExtensions.cs b/src/Jamq.Client/MethodInfoExtensions.cs new file mode 100644 index 0000000..2e113ae --- /dev/null +++ b/src/Jamq.Client/MethodInfoExtensions.cs @@ -0,0 +1,9 @@ +using System.Reflection; + +namespace Jamq.Client; + +internal static class MethodInfoExtensions +{ + public static TResult CreateDelegate(this MethodInfo methodInfo, object instance) + where TResult : Delegate => (TResult)methodInfo.CreateDelegate(typeof(TResult), instance); +} \ No newline at end of file diff --git a/src/Jamq.Client/Producing/ProducerBuilder.cs b/src/Jamq.Client/Producing/ProducerBuilder.cs index b10dea3..8bbe889 100644 --- a/src/Jamq.Client/Producing/ProducerBuilder.cs +++ b/src/Jamq.Client/Producing/ProducerBuilder.cs @@ -144,7 +144,7 @@ public IProducerBuilder Flush() var parameters = methodInfo.GetParameters(); if (parameters.Length < 2 || - !parameters.First().ParameterType.IsAssignableTo(typeof(ProducerContext)) || + !typeof(ProducerContext).IsAssignableFrom(parameters.First().ParameterType) || parameters.Last().ParameterType != typeof(CancellationToken)) { throw ProducerBuilderMiddlewareConventionException.MismatchParameters(type); @@ -160,7 +160,7 @@ public IProducerBuilder Flush() (context, ct) => next((ProducerContext)context, ct)); if (parameters.Length == 2) { - return methodInfo.CreateDelegate(instance).Invoke; + return ((ProducerDelegate) methodInfo.CreateDelegate(typeof(ProducerDelegate), instance)).Invoke; } var factory = MiddlewareCompiler