Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Liquid framework for net8. #239

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class IServiceCollectionExtension

/// <summary>
/// Register a <see cref="KafkaConsumer{TEntity}"/> with its dependency, and with
/// <see cref="IServiceCollectionLiquidExtension.AddScopedLiquidTelemetry{TInterface, TService}(IServiceCollection)"/>.
/// <see cref="IServiceCollectionLiquidExtension.AddSingletonLiquidTelemetry{TInterface, TService}(IServiceCollection)"/>.
/// </summary>
/// <typeparam name="TEntity">Type of entity that will be consumed by this service instance.</typeparam>
/// <param name="services">Extended service collection instance.</param>
Expand All @@ -25,23 +25,19 @@ public static class IServiceCollectionExtension
public static IServiceCollection AddLiquidKafkaProducer<TEntity>(this IServiceCollection services, string sectionName, bool activateTelemetry = true)
{
services.TryAddTransient<IKafkaFactory, KafkaFactory>();
services.AddOptions<KafkaSettings>()
.Configure<IConfiguration>((settings, configuration) =>
{
configuration.GetSection(sectionName).Bind(settings);
});
if (activateTelemetry)
{
services.AddScoped((provider) =>
{
var settings = provider.GetService<IConfiguration>().GetSection(sectionName).Get<KafkaSettings>();
return ActivatorUtilities.CreateInstance<KafkaProducer<TEntity>>(provider, settings);
});

services.AddScopedLiquidTelemetry<ILiquidProducer<TEntity>, KafkaProducer<TEntity>>();
services.AddSingleton<KafkaProducer<TEntity>>();
services.AddSingletonLiquidTelemetry<ILiquidProducer<TEntity>, KafkaProducer<TEntity>>();
}
else
{
services.AddScoped<ILiquidProducer<TEntity>>((provider) =>
{
var settings = provider.GetService<IConfiguration>().GetSection(sectionName).Get<KafkaSettings>();
return ActivatorUtilities.CreateInstance<KafkaProducer<TEntity>>(provider, settings);
});
services.AddSingleton<ILiquidProducer<TEntity>, KafkaProducer<TEntity>>();
}

return services;
Expand Down Expand Up @@ -72,8 +68,7 @@ public static IServiceCollection AddLiquidKafkaConsumer<TWorker, TEntity>(this I
/// <summary>
/// Register a <see cref="KafkaConsumer{TEntity}"/> service with its dependency, and with
/// <see cref="IServiceCollectionLiquidExtension.AddLiquidTelemetryInterceptor{TInterface, TService}(IServiceCollection)"/>.
/// In order for consumers injected by this method to work correctly, you will need to register the Liquid settings
/// <see cref="IServiceCollectionLiquidExtension.AddLiquidConfiguration(IServiceCollection)"/> and
/// In order for consumers injected by this method to work correctly and
/// domain handlers/services in your build configurator.
/// </summary>
/// <typeparam name="TWorker">Type of implementation from <see cref="ILiquidWorker{TEntity}"/></typeparam>
Expand All @@ -95,27 +90,24 @@ private static IServiceCollection AddConsumer<TEntity>(this IServiceCollection s
{
services.AddTransient<IKafkaFactory, KafkaFactory>();

services.AddOptions<KafkaSettings>()
.Configure<IConfiguration>((settings, configuration) =>
{
configuration.GetSection(sectionName).Bind(settings);
});

if (activateTelemetry)
{
services.AddSingleton((provider) =>
{
var settings = provider.GetService<IConfiguration>().GetSection(sectionName).Get<KafkaSettings>();
return ActivatorUtilities.CreateInstance<KafkaConsumer<TEntity>>(provider, settings);
});
services.AddSingleton<KafkaConsumer<TEntity>>();


services.AddSingletonLiquidTelemetry<ILiquidConsumer<TEntity>, KafkaConsumer<TEntity>>();
}
else
{
services.AddSingleton<ILiquidConsumer<TEntity>>((provider) =>
{
var settings = provider.GetService<IConfiguration>().GetSection(sectionName).Get<KafkaSettings>();
return ActivatorUtilities.CreateInstance<KafkaConsumer<TEntity>>(provider, settings);
});
services.AddSingleton<ILiquidConsumer<TEntity>, KafkaConsumer<TEntity>>();
}


return services;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Liquid.Messaging.Kafka/KafkaConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading;
using System.Threading.Tasks;
using Liquid.Core.Entities;
using Microsoft.Extensions.Options;

namespace Liquid.Messaging.Kafka
{
Expand All @@ -33,10 +34,10 @@ public class KafkaConsumer<TEntity> : ILiquidConsumer<TEntity>
/// <param name="kafkaFactory">Kafka client provider service.</param>
/// <param name="kafkaSettings">Configuration properties set.</param>
/// <exception cref="ArgumentNullException"></exception>
public KafkaConsumer(IKafkaFactory kafkaFactory, KafkaSettings kafkaSettings)
public KafkaConsumer(IKafkaFactory kafkaFactory, IOptions<KafkaSettings> kafkaSettings)
{
_factory = kafkaFactory ?? throw new ArgumentNullException(nameof(kafkaFactory));
_settings = kafkaSettings ?? throw new ArgumentNullException(nameof(kafkaSettings));
_settings = kafkaSettings?.Value ?? throw new ArgumentNullException(nameof(kafkaSettings));
}

///<inheritdoc/>
Expand Down
7 changes: 4 additions & 3 deletions src/Liquid.Messaging.Kafka/KafkaProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;

namespace Liquid.Messaging.Kafka
{
Expand All @@ -24,16 +25,16 @@ public class KafkaProducer<TEntity> : ILiquidProducer<TEntity>
/// <param name="settings"></param>
/// <param name="factory"></param>
/// <exception cref="ArgumentNullException"></exception>
public KafkaProducer(KafkaSettings settings, IKafkaFactory factory)
public KafkaProducer(IOptions<KafkaSettings> settings, IKafkaFactory factory)
{
if (factory is null)
{
throw new ArgumentNullException(nameof(factory));
}

_settings = settings;
_settings = settings?.Value ?? throw new ArgumentNullException(nameof(settings));

_client = factory.GetProducer(settings);
_client = factory.GetProducer(_settings);
}

///<inheritdoc/>
Expand Down
13 changes: 5 additions & 8 deletions src/Liquid.Messaging.Kafka/Liquid.Messaging.Kafka.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<PackageId>Liquid.Messaging.Kafka</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Authors>Avanade Brazil</Authors>
Expand All @@ -10,7 +10,7 @@
<Copyright>Avanade 2019</Copyright>
<PackageProjectUrl>https://github.com/Avanade/Liquid-Application-Framework</PackageProjectUrl>
<PackageIcon>logo.png</PackageIcon>
<Version>6.0.0</Version>
<Version>8.0.0-alpha-01</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Description>
The Liquid.Messaging.Kafka provides producer and consumer patterns to allow the send and consumption of Messaging inside your microservice.
Expand All @@ -27,11 +27,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Confluent.Kafka" Version="1.9.2" />
<PackageReference Include="Confluent.Kafka" Version="2.4.0" />
<PackageReference Include="Liquid.Core" Version="8.0.0-alpha-04" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Liquid.Core\Liquid.Core.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class IServiceCollectionExtension

/// <summary>
/// Register a <see cref="RabbitMqConsumer{TEntity}"/> with its dependency, and with
/// <see cref="IServiceCollectionLiquidExtension.AddScopedLiquidTelemetry{TInterface, TService}(IServiceCollection)"/>.
/// <see cref="IServiceCollectionLiquidExtension.AddSingletonLiquidTelemetry{TInterface, TService}(IServiceCollection)"/>.
/// </summary>
/// <typeparam name="TEntity">Type of entity that will be consumed by this service instance.</typeparam>
/// <param name="services">Extended service collection instance.</param>
Expand All @@ -26,23 +26,20 @@ public static IServiceCollection AddLiquidRabbitMqProducer<TEntity>(this IServic
{
services.TryAddTransient<IRabbitMqFactory, RabbitMqFactory>();

if (activateTelemetry)
services.AddOptions<RabbitMqProducerSettings>()
.Configure<IConfiguration>((settings, configuration) =>
{
services.AddScoped((provider) =>
{
var settings = provider.GetService<IConfiguration>().GetSection(sectionName).Get<RabbitMqProducerSettings>();
return ActivatorUtilities.CreateInstance<RabbitMqProducer<TEntity>>(provider, settings);
});
configuration.GetSection(sectionName).Bind(settings);
});

services.AddScopedLiquidTelemetry<ILiquidProducer<TEntity>, RabbitMqProducer<TEntity>>();
if (activateTelemetry)
{
services.AddSingleton<RabbitMqProducer<TEntity>>();
services.AddSingletonLiquidTelemetry<ILiquidProducer<TEntity>, RabbitMqProducer<TEntity>>();
}
else
{
services.AddScoped<ILiquidProducer<TEntity>>((provider) =>
{
var settings = provider.GetService<IConfiguration>().GetSection(sectionName).Get<RabbitMqProducerSettings>();
return ActivatorUtilities.CreateInstance<RabbitMqProducer<TEntity>>(provider, settings);
});
services.AddSingleton<ILiquidProducer<TEntity>, RabbitMqProducer<TEntity>>();
}

return services;
Expand Down Expand Up @@ -73,8 +70,7 @@ public static IServiceCollection AddLiquidRabbitMqConsumer<TWorker, TEntity>(thi
/// <summary>
/// Register a <see cref="RabbitMqConsumer{TEntity}"/> service with its dependency, and with
/// <see cref="IServiceCollectionLiquidExtension.AddLiquidTelemetryInterceptor{TInterface, TService}(IServiceCollection)"/>.
/// In order for consumers injected by this method to work correctly, you will need to register the Liquid settings
/// <see cref="IServiceCollectionLiquidExtension.AddLiquidConfiguration(IServiceCollection)"/> and
/// In order for consumers injected by this method to work correctly, you will need to register the Liquid settings and
/// domain handlers/services in your build configurator.
/// </summary>
/// <typeparam name="TWorker">Type of implementation from <see cref="ILiquidWorker{TEntity}"/></typeparam>
Expand All @@ -96,24 +92,21 @@ private static IServiceCollection AddConsumer<TEntity>(this IServiceCollection s
{
services.AddSingleton<IRabbitMqFactory, RabbitMqFactory>();

if (activateTelemetry)
services.AddOptions<RabbitMqConsumerSettings>()
.Configure<IConfiguration>((settings, configuration) =>
{
services.AddSingleton((provider) =>
{
var settings = provider.GetService<IConfiguration>().GetSection(sectionName).Get<RabbitMqConsumerSettings>();
return ActivatorUtilities.CreateInstance<RabbitMqConsumer<TEntity>>(provider, settings);
});
configuration.GetSection(sectionName).Bind(settings);
});

if (activateTelemetry)
{
services.AddSingleton<RabbitMqConsumer<TEntity>>();

services.AddSingletonLiquidTelemetry<ILiquidConsumer<TEntity>, RabbitMqConsumer<TEntity>>();
}
else
{
services.AddSingleton<ILiquidConsumer<TEntity>>((provider) =>
{
var settings = provider.GetService<IConfiguration>().GetSection(sectionName).Get<RabbitMqConsumerSettings>();
return ActivatorUtilities.CreateInstance<RabbitMqConsumer<TEntity>>(provider, settings);
});
services.AddSingleton<ILiquidConsumer<TEntity>, RabbitMqConsumer<TEntity>>();
}


Expand Down
10 changes: 4 additions & 6 deletions src/Liquid.Messaging.RabbitMq/Liquid.Messaging.RabbitMq.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<PackageId>Liquid.Messaging.RabbitMq</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Authors>Avanade Brazil</Authors>
Expand All @@ -9,7 +9,7 @@
<Copyright>Avanade 2019</Copyright>
<PackageProjectUrl>https://github.com/Avanade/Liquid-Application-Framework</PackageProjectUrl>
<PackageIcon>logo.png</PackageIcon>
<Version>6.0.0</Version>
<Version>8.0.0-alpha-01</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Description>
The Liquid.Messaging.RabbitMq provides producer and consumer patterns to allow the send and consumption of Messaging inside your microservice.
Expand All @@ -20,7 +20,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4" />
<PackageReference Include="Liquid.Core" Version="8.0.0-alpha-04" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="RabbitMQ.Client" Version="6.8.1" />
</ItemGroup>

Expand All @@ -31,7 +32,4 @@
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Liquid.Core\Liquid.Core.csproj" />
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions src/Liquid.Messaging.RabbitMq/RabbitMqConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Liquid.Core.Interfaces;
using Liquid.Core.Utils;
using Liquid.Messaging.RabbitMq.Settings;
using Microsoft.Extensions.Options;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System;
Expand All @@ -29,17 +30,17 @@
public event Func<ConsumerMessageEventArgs<TEntity>, CancellationToken, Task> ConsumeMessageAsync;

///<inheritdoc/>
public event Func<ConsumerErrorEventArgs, Task> ProcessErrorAsync;

Check warning on line 33 in src/Liquid.Messaging.RabbitMq/RabbitMqConsumer.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

The event 'RabbitMqConsumer<TEntity>.ProcessErrorAsync' is never used

Check warning on line 33 in src/Liquid.Messaging.RabbitMq/RabbitMqConsumer.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

The event 'RabbitMqConsumer<TEntity>.ProcessErrorAsync' is never used

Check warning on line 33 in src/Liquid.Messaging.RabbitMq/RabbitMqConsumer.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

The event 'RabbitMqConsumer<TEntity>.ProcessErrorAsync' is never used

/// <summary>
/// Initilize an instance of <see cref="RabbitMqConsumer{TEntity}"/>
/// </summary>
/// <param name="factory">RabbitMq client factory.</param>
/// <param name="settings">Configuration properties set.</param>
public RabbitMqConsumer(IRabbitMqFactory factory, RabbitMqConsumerSettings settings)
public RabbitMqConsumer(IRabbitMqFactory factory, IOptions<RabbitMqConsumerSettings> settings)
{
_factory = factory ?? throw new ArgumentNullException(nameof(factory));
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
_settings = settings?.Value ?? throw new ArgumentNullException(nameof(settings));

_autoAck = _settings.AdvancedSettings?.AutoAck ?? true;
}
Expand Down
7 changes: 4 additions & 3 deletions src/Liquid.Messaging.RabbitMq/RabbitMqProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;

namespace Liquid.Messaging.RabbitMq
{
Expand All @@ -23,17 +24,17 @@ public class RabbitMqProducer<TEntity> : ILiquidProducer<TEntity>
/// <param name="factory"></param>
/// <param name="settings"></param>
/// <exception cref="MessagingMissingConfigurationException"></exception>
public RabbitMqProducer(IRabbitMqFactory factory, RabbitMqProducerSettings settings)
public RabbitMqProducer(IRabbitMqFactory factory, IOptions<RabbitMqProducerSettings> settings)
{
if (factory is null)
{
throw new ArgumentNullException(nameof(factory));
}

_settings = settings ?? throw new ArgumentNullException(nameof(settings));
_settings = settings?.Value ?? throw new ArgumentNullException(nameof(settings));


_channelModel = factory.GetSender(settings);
_channelModel = factory.GetSender(_settings);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class IServiceCollectionExtensions
{
/// <summary>
/// Register a <see cref="ServiceBusConsumer{TEntity}"/> with its dependency, and with
/// <see cref="IServiceCollectionLiquidExtension.AddLiquidTelemetryInterceptor{TInterface, TService}(IServiceCollection)"/>.
/// <see cref="IServiceCollectionLiquidExtension.AddSingletonLiquidTelemetry{TInterface, TService}(IServiceCollection)"/>.
/// </summary>
/// <typeparam name="TEntity">Type of entity that will be consumed by this service instance.</typeparam>
/// <param name="services">Extended service collection instance.</param>
Expand All @@ -37,16 +37,16 @@ public static IServiceCollection AddLiquidServiceBusProducer<TEntity>(this IServ

if (activateTelemetry)
{
services.AddScoped((provider) =>
services.AddSingleton((provider) =>
{
return ActivatorUtilities.CreateInstance<ServiceBusProducer<TEntity>>(provider, entityPath);
});

services.AddScopedLiquidTelemetry<ILiquidProducer<TEntity>, ServiceBusProducer<TEntity>>();
services.AddSingletonLiquidTelemetry<ILiquidProducer<TEntity>, ServiceBusProducer<TEntity>>();
}
else
{
services.AddScoped<ILiquidProducer<TEntity>>((provider) =>
services.AddSingleton<ILiquidProducer<TEntity>>((provider) =>
{
return ActivatorUtilities.CreateInstance<ServiceBusProducer<TEntity>>(provider, entityPath);
});
Expand Down Expand Up @@ -90,8 +90,7 @@ public static IServiceCollection AddLiquidServiceBusConsumer<TWorker, TEntity>(t
/// <summary>
/// Register a <see cref="ServiceBusConsumer{TEntity}"/> service with its dependency, and with
/// <see cref="IServiceCollectionLiquidExtension.AddLiquidTelemetryInterceptor{TInterface, TService}(IServiceCollection)"/>.
/// In order for consumers injected by this method to work correctly, you will need to register the Liquid settings
/// <see cref="IServiceCollectionLiquidExtension.AddLiquidConfiguration(IServiceCollection)"/> and
/// In order for consumers injected by this method to work correctly and
/// domain handlers/services in your build configurator.
/// </summary>
/// <typeparam name="TWorker">Type of implementation from <see cref="ILiquidWorker{TEntity}"/></typeparam>
Expand Down
Loading
Loading