Skip to content

Commit

Permalink
add support for .net 9
Browse files Browse the repository at this point in the history
  • Loading branch information
stormaref committed Jan 2, 2025
1 parent 9ca5cac commit 0849571
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0.x'
dotnet-version: '9.0.x'
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
8 changes: 4 additions & 4 deletions KafkaStorm.Test/KafkaStorm.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand All @@ -10,13 +10,13 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PackageReference Include="coverlet.collector" Version="6.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion KafkaStorm.Test/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private IServiceCollection ConfigureServices()
{
prf.ConfigProducer(new ProducerConfig {BootstrapServers = "localhost:29092",});

prf.InMemoryQueue();
ProducerRegistrationFactory.InMemoryQueue();

prf.SetQueueLimit(65536);
});
Expand Down
7 changes: 1 addition & 6 deletions KafkaStorm/Exceptions/ConsumerNotConfiguredException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@

namespace KafkaStorm.Exceptions;

public class ConsumerNotConfiguredException : Exception
{
public ConsumerNotConfiguredException() : base("Consumer is not configured")
{
}
}
public class ConsumerNotConfiguredException() : Exception("Consumer is not configured");
7 changes: 1 addition & 6 deletions KafkaStorm/Exceptions/DuplicateConsumerException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@

namespace KafkaStorm.Exceptions;

public class DuplicateConsumerException : Exception
{
public DuplicateConsumerException(string name) : base($"Consumer added more than once ({name})")
{
}
}
public class DuplicateConsumerException(string name) : Exception($"Consumer added more than once ({name})");
8 changes: 2 additions & 6 deletions KafkaStorm/Exceptions/MessageNullException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@

namespace KafkaStorm.Exceptions;

public class MessageNullException<TMessage> : ArgumentNullException
{
public MessageNullException() : base("Message", $"Message of type {typeof(TMessage)} was null")
{
}
}
public class MessageNullException<TMessage>()
: ArgumentNullException("Message", $"Message of type {typeof(TMessage)} was null");
7 changes: 1 addition & 6 deletions KafkaStorm/Exceptions/ProducerConfigNullException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@

namespace KafkaStorm.Exceptions;

public class ProducerConfigNullException : Exception
{
public ProducerConfigNullException() : base("Producer Config is null")
{
}
}
public class ProducerConfigNullException() : Exception("Producer Config is null");
12 changes: 6 additions & 6 deletions KafkaStorm/KafkaStorm.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Authors>ArefAzizian</Authors>
<Version>8.1.0</Version>
<Version>9.0.0</Version>
<PackageId>KafKaStorm</PackageId>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand All @@ -22,9 +22,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Confluent.Kafka" Version="2.3.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Confluent.Kafka" Version="2.6.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.0" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion KafkaStorm/Registration/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void AddConsumersFromAssembly(this ConsumerRegistrationFactory crf
var method = typeof(ConsumerRegistrationFactory).GetMethod("AddConsumer");
var methodInfos = (from messageType in messageTypes
let consumerType = GetConsumerType(assembly, messageType)
where consumerType != default
where consumerType != null
select method!.MakeGenericMethod(consumerType, messageType))
.ToList();
foreach (var generic in methodInfos)
Expand Down
2 changes: 1 addition & 1 deletion KafkaStorm/Registration/ProducerRegistrationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void SetQueueLimit(uint count)
MaximumQueueMessageCount = count;
}

public void InMemoryQueue(bool activate = true)
public static void InMemoryQueue(bool activate = true)
{
UseInMemoryQueue = activate;
}
Expand Down
5 changes: 3 additions & 2 deletions KafkaStorm/Services/ConsumerHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ public ConsumerHostedService(IConsumer<TMessage> myConsumer)
_myConsumer = myConsumer;

var fullName = _myConsumer.GetType().FullName;
ArgumentException.ThrowIfNullOrEmpty(fullName);

var succeeded =
ConsumerRegistrationFactory.ConsumerConfigs.TryGetValue(fullName, out var config) &&
ConsumerRegistrationFactory.ConsumerTopics.TryGetValue(fullName, out _topicName);
ConsumerRegistrationFactory.ConsumerTopics.TryGetValue(fullName, out _topicName!);

_consumer = new ConsumerBuilder<Ignore, string>(succeeded
? config
Expand Down Expand Up @@ -53,7 +54,7 @@ private void Handle(CancellationToken cancellationToken)
var result = _consumer.Consume(ConsumerRegistrationFactory.ConsumingPeriod);
if (result == null)
return;

var message = JsonSerializer.Deserialize<TMessage>(result.Message.Value) ??
throw new MessageNullException<TMessage>();
_myConsumer.Handle(message, cancellationToken);
Expand Down
2 changes: 1 addition & 1 deletion KafkaStorm/Services/MessageStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public MessageStore()

public (Guid id, StoredMessage? message) GetLastMessage()
{
if (!_dictionary.Any()) return (Guid.Empty, default);
if (_dictionary.IsEmpty) return (Guid.Empty, null);

var (key, value) = _dictionary.Last();
return (key, value);
Expand Down
7 changes: 2 additions & 5 deletions KafkaStorm/Services/Producer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ public async Task ProduceNowAsync<TMessage>(TMessage message, string? topicName

public async Task ProduceNowAsync(StoredMessage message)
{
if (message is null)
{
throw new ArgumentNullException(nameof(message));
}
ArgumentNullException.ThrowIfNull(message);

var dr = await _producer.ProduceAsync(message.Topic, new Message<Null, string>
await _producer.ProduceAsync(message.Topic, new Message<Null, string>
{
Value = JsonSerializer.Serialize(message.Body)
});
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Simple .net client for Kafka based on **Confluent.Kafka**

### Using package manager:
```
Install-Package KafkaStorm -Version 8.1.0
Install-Package KafkaStorm -Version 9.0.0
```

# Usage/Examples
Expand Down

0 comments on commit 0849571

Please sign in to comment.