diff --git a/Sod.Infrastructure/Sod.Infrastructure.csproj b/Sod.Infrastructure/Sod.Infrastructure.csproj
index ea33bbd..88ef08a 100644
--- a/Sod.Infrastructure/Sod.Infrastructure.csproj
+++ b/Sod.Infrastructure/Sod.Infrastructure.csproj
@@ -1,15 +1,15 @@
- net6.0
+ net9.0
enable
-
-
-
-
+
+
+
+
diff --git a/Sod.Model/Events/Outgoing/Mqtt/MqttOutgoingEventPublisher.cs b/Sod.Model/Events/Outgoing/Mqtt/MqttOutgoingEventPublisher.cs
index 93efeab..7fe12c5 100644
--- a/Sod.Model/Events/Outgoing/Mqtt/MqttOutgoingEventPublisher.cs
+++ b/Sod.Model/Events/Outgoing/Mqtt/MqttOutgoingEventPublisher.cs
@@ -1,23 +1,18 @@
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging;
using MQTTnet;
-using MQTTnet.Client.Publishing;
+using MQTTnet.Client;
using Sod.Infrastructure.Capabilities;
-using Sod.Model.CommonTypes;
namespace Sod.Model.Events.Outgoing.Mqtt;
public class MqttOutgoingEventPublisher : LoggingCapability, IOutgoingEventPublisher
{
- private readonly IApplicationMessagePublisher _publisher;
+ private readonly IMqttClient _client;
private readonly OutgoingEventMappings _mappings;
- public MqttOutgoingEventPublisher(IApplicationMessagePublisher publisher, OutgoingEventMappings mappings)
+ public MqttOutgoingEventPublisher(IMqttClient client, OutgoingEventMappings mappings)
{
- _publisher = publisher;
+ _client = client;
_mappings = mappings;
}
@@ -31,7 +26,7 @@ public async Task> PublishAsync(OutgoingEvent e
.WithTopic(topic)
.WithPayload(evnt.Value)
.Build();
- var publishResult = await _publisher.PublishAsync(msg, CancellationToken.None);
+ var publishResult = await _client.PublishAsync(msg);
if (publishResult.ReasonCode != MqttClientPublishReasonCode.Success) failed.Add(new FailedOutgoingEvent(evnt, FailedOutgoingEventReason.CommunicationError));
}
diff --git a/Sod.Model/Sod.Model.csproj b/Sod.Model/Sod.Model.csproj
index 61a2145..aa14e06 100644
--- a/Sod.Model/Sod.Model.csproj
+++ b/Sod.Model/Sod.Model.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net9.0
enable
enable
diff --git a/Sod.Tests/Sod.Tests.csproj b/Sod.Tests/Sod.Tests.csproj
index 0f63a62..597e6e3 100644
--- a/Sod.Tests/Sod.Tests.csproj
+++ b/Sod.Tests/Sod.Tests.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net9.0
false
@@ -9,15 +9,15 @@
-
-
-
-
-
+
+
+
+
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/Sod.Worker/Modules/InfrastructureModule.cs b/Sod.Worker/Modules/InfrastructureModule.cs
index 7c0bb5b..31367a4 100644
--- a/Sod.Worker/Modules/InfrastructureModule.cs
+++ b/Sod.Worker/Modules/InfrastructureModule.cs
@@ -1,11 +1,12 @@
using System;
using System.IO;
using System.Linq;
+using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Autofac;
using MQTTnet;
-using MQTTnet.Client.Options;
+using MQTTnet.Client;
using MQTTnet.Extensions.ManagedClient;
using Sod.Infrastructure.Satel.Communication;
using Sod.Infrastructure.Satel.Socket;
@@ -56,60 +57,56 @@ protected override void Load(ContainerBuilder builder)
.WithCredentials(cfg.User, cfg.Password)
.WithTcpServer(cfg.Host, cfg.Port);
if (cfg.CrtPath != null)
- optionsBuilder.WithTls(x =>
+ optionsBuilder.WithTlsOptions(opt =>
{
- var caCrt = new X509Certificate2(File.ReadAllBytes(cfg.CrtPath));
- x.UseTls = true;
- x.SslProtocol = System.Security.Authentication.SslProtocols.Tls12;
- x.CertificateValidationHandler = certContext =>
- {
- var chain = new X509Chain();
- chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
- chain.ChainPolicy.RevocationFlag = X509RevocationFlag.ExcludeRoot;
- chain.ChainPolicy.VerificationFlags = X509VerificationFlags.NoFlag;
- chain.ChainPolicy.VerificationTime = DateTime.Now;
- chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 0, 0);
-
- chain.ChainPolicy.CustomTrustStore.Add(caCrt);
- chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
-
- // convert provided X509Certificate to X509Certificate2
- var x5092 = new X509Certificate2(certContext.Certificate);
-
- return chain.Build(x5092);
- };
+ var caCrt = X509CertificateLoader.LoadCertificate(File.ReadAllBytes(cfg.CrtPath));
+ opt
+ .UseTls()
+ .WithSslProtocols(SslProtocols.Tls12 | SslProtocols.Tls13)
+ .WithCertificateValidationHandler(certContext =>
+ {
+ var chain = new X509Chain();
+ chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
+ chain.ChainPolicy.RevocationFlag = X509RevocationFlag.ExcludeRoot;
+ chain.ChainPolicy.VerificationFlags = X509VerificationFlags.NoFlag;
+ chain.ChainPolicy.VerificationTime = DateTime.Now;
+ chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 0, 0);
+
+ chain.ChainPolicy.CustomTrustStore.Add(caCrt);
+ chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
+ // convert provided X509Certificate to X509Certificate2
+ var x5092 = new X509Certificate2(certContext.Certificate);
+
+ return chain.Build(x5092);
+ });
});
return optionsBuilder.Build();
})
- .As()
+ .As()
.SingleInstance();
builder
.Register(ctx =>
new ManagedMqttClientOptionsBuilder()
.WithAutoReconnectDelay(TimeSpan.FromSeconds(2))
- .WithClientOptions(ctx.Resolve())
+ .WithClientOptions(ctx.Resolve())
.Build())
- .As()
+ .As()
.SingleInstance();
builder.RegisterType().As().SingleInstance();
builder
.Register(_ => new MqttFactory().CreateManagedMqttClient())
- .As()
- .As()
+ .As()
.SingleInstance()
.OnActivated(async activatedEventArgs =>
{
var client = activatedEventArgs.Instance;
- await client.StartAsync(activatedEventArgs.Context.Resolve());
var mappings = activatedEventArgs.Context.Resolve();
foreach (var topic in mappings.Topics) await client.SubscribeAsync(topic);
-
- var broker = activatedEventArgs.Context.Resolve();
- client.UseApplicationMessageReceivedHandler(x => { broker.Process(x.ApplicationMessage.Topic, Encoding.UTF8.GetString(x.ApplicationMessage.Payload)); });
+ await client.StartAsync(activatedEventArgs.Context.Resolve());
});
builder.RegisterType().As().SingleInstance();
diff --git a/Sod.Worker/Sod.Worker.csproj b/Sod.Worker/Sod.Worker.csproj
index 734f9a0..5aa1529 100644
--- a/Sod.Worker/Sod.Worker.csproj
+++ b/Sod.Worker/Sod.Worker.csproj
@@ -1,22 +1,22 @@
- net6.0
+ net9.0
dotnet-Sod.Service-7247485F-D30A-418F-98AE-4EC2930457F3
Linux
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/global.json b/global.json
deleted file mode 100644
index 97dd873..0000000
--- a/global.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "sdk": {
- "version": "6.0",
- "rollForward": "latestMajor",
- "allowPrerelease": false
- }
-}
\ No newline at end of file