Skip to content

Commit 8e26091

Browse files
committed
Updated MQTTnet and OpcUa-client to latest major.
1 parent 149f6fa commit 8e26091

File tree

11 files changed

+31
-27
lines changed

11 files changed

+31
-27
lines changed

Directory.Packages.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@
5454

5555
<!-- Dependencies for drivers and adapters -->
5656
<PackageVersion Include="System.IO.Ports" Version="10.0.0" />
57-
<PackageVersion Include="MQTTnet" Version="4.3.1.873" />
58-
<PackageVersion Include="OPCFoundation.NetStandard.Opc.Ua.Client" Version="1.5.376.213" />
57+
<PackageVersion Include="MQTTnet" Version="5.0.1.1416" />
58+
<PackageVersion Include="OPCFoundation.NetStandard.Opc.Ua.Client" Version="1.5.377.21" />
5959

6060
<PackageVersion Include="InfluxDB.LineProtocol" Version="1.1.0" />
6161
<PackageVersion Include="InfluxDB.Client" Version="4.18.0" />
62-
<PackageVersion Include="CsvHelper" Version="33.0.0" />
62+
<PackageVersion Include="CsvHelper" Version="33.1.0" />
6363

6464
<PackageVersion Include="MimeTypeMapOfficial" Version="1.0.17" />
6565
<PackageVersion Include="SixLabors.ImageSharp" Version="3.1.12" />

src/Moryx.Drivers.Mqtt/MqttDriver.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright (c) 2025, Phoenix Contact GmbH & Co. KG
22
// Licensed under the Apache License, Version 2.0
33

4+
using System.Buffers;
45
using System.Runtime.Serialization;
56
using Moryx.AbstractionLayer.Drivers;
67
using MQTTnet;
7-
using MQTTnet.Client;
88
using System.ComponentModel;
99
using System.Text.RegularExpressions;
1010
using Moryx.AbstractionLayer.Drivers.Message;
@@ -146,7 +146,7 @@ protected override void OnInitialize()
146146
{
147147
base.OnInitialize();
148148

149-
var factory = new MqttFactory();
149+
var factory = new MqttClientFactory();
150150
_mqttClient = factory.CreateMqttClient();
151151

152152
_mqttClient.ApplicationMessageReceivedAsync += OnReceived;
@@ -339,14 +339,17 @@ public async Task OnSend(MqttMessageTopic messageTopic, byte[] message, Cancella
339339
private Task OnReceived(MqttApplicationMessageReceivedEventArgs args)
340340
{
341341
// Experimental: Dispatch to new thread to prevent exceptions or deadlocks from causing inflight blockage
342-
ParallelOperations.ExecuteParallel(param => Receive(param.Topic, param.Payload), new { args.ApplicationMessage.Topic, args.ApplicationMessage.Payload });
342+
ParallelOperations.ExecuteParallel(param => Receive(param.Topic, param.Payload), new
343+
{
344+
args.ApplicationMessage.Topic,
345+
Payload = args.ApplicationMessage.Payload.ToArray()
346+
});
343347

344348
return Task.CompletedTask;
345349
}
346350

347351
internal void Receive(string topicName, byte[] message)
348352
{
349-
350353
var topic = topicName;
351354
if (Identifier != "")
352355
{

src/Moryx.Drivers.OpcUa/ApplicationConfigurationFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public virtual async Task<ApplicationConfiguration> Create(ILogger logger, strin
2727
var filePath = string.IsNullOrEmpty(configPath) ? defaultPath : configPath;
2828
try
2929
{
30-
config = await application.LoadApplicationConfiguration(filePath, false);
30+
config = await application.LoadApplicationConfigurationAsync(filePath, false);
3131
}
3232
catch (Exception ex)
3333
{
@@ -37,7 +37,7 @@ public virtual async Task<ApplicationConfiguration> Create(ILogger logger, strin
3737

3838
ApplicationName = config.ApplicationName;
3939
// check the application certificate
40-
var haveAppCertificate = await application.CheckApplicationInstanceCertificate(false, 0);
40+
var haveAppCertificate = await application.CheckApplicationInstanceCertificatesAsync(false, 0);
4141
if (!haveAppCertificate)
4242
{
4343
throw new Exception("Application instance certificate invalid!");

src/Moryx.Operators.Management/Moryx.Operators.Management.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<ProjectReference Include="..\Moryx.Model.PostgreSQL\Moryx.Model.PostgreSQL.csproj"/>
2020
<ProjectReference Include="..\Moryx.Model.Sqlite\Moryx.Model.Sqlite.csproj"/>
2121
<ProjectReference Include="..\Moryx.Operators\Moryx.Operators.csproj"/>
22+
<ProjectReference Include="..\Moryx.Runtime.Kernel\Moryx.Runtime.Kernel.csproj" />
2223
<ProjectReference Include="..\Moryx.Users\Moryx.Users.csproj"/>
2324
</ItemGroup>
2425

src/Moryx.Shifts.Management/Moryx.Shifts.Management.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<ItemGroup>
1515
<ProjectReference Include="..\Moryx.Model.PostgreSQL\Moryx.Model.PostgreSQL.csproj" />
1616
<ProjectReference Include="..\Moryx.Model.Sqlite\Moryx.Model.Sqlite.csproj" />
17+
<ProjectReference Include="..\Moryx.Runtime.Kernel\Moryx.Runtime.Kernel.csproj" />
1718
<ProjectReference Include="..\Moryx.Shifts\Moryx.Shifts.csproj" />
1819
</ItemGroup>
1920

src/Tests/Moryx.Drivers.OpcUa.Tests/HandlingWriteAndRead.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Moryx.Modules;
77
using NUnit.Framework;
88
using Opc.Ua;
9+
using Opc.Ua.Client;
910

1011
namespace Moryx.Drivers.OpcUa.Tests;
1112

@@ -124,7 +125,7 @@ public void TestFindNode()
124125
//Act
125126
var result = _driver.FindNodeId(node.DisplayName.ToString());
126127

127-
//Assert
128+
//Assert
128129
Assert.That(result.Any(x => x.Equals(nodeId)), Is.True);
129130
}
130131
}

src/Tests/Moryx.Recources.Mqtt.Tests/TestDriverMqttChannelFunctions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using Moryx.TestTools.UnitTest;
1818
using Moryx.Tools;
1919
using MQTTnet;
20-
using MQTTnet.Client;
2120
using MQTTnet.Formatter;
2221
using MQTTnet.Packets;
2322
using MQTTnet.Protocol;
@@ -50,7 +49,7 @@ public void Setup()
5049
_driver = CreateMqttDriver();
5150
_mockClient = SetupMqttClientMock();
5251

53-
//Initialize MqttDriver
52+
//Initialize MqttDriver
5453
_driver.InitializeForTest(_mockClient.Object);
5554
((IPlugin)_driver).Start();
5655
_driver.OnConnected(new MqttClientConnectedEventArgs(new MqttClientConnectResult())).Wait();
@@ -122,7 +121,7 @@ public void Channel_FindChannel_TChannel()
122121
Assert.That(c.Identifier.Equals(_topicBoolMqtt.Identifier));
123122
}
124123

125-
124+
126125
[Test(Description = "Return null, if identifier does not exist")]
127126
public void Channel_NotFindChannel_IdentifierDoesNotExist()
128127
{

src/Tests/Moryx.Recources.Mqtt.Tests/TestDriverMqttIByteSerializable.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0
33

44
using System;
5+
using System.Buffers;
56
using System.Linq.Expressions;
67
using System.Threading;
78
using System.Threading.Tasks;
@@ -15,7 +16,6 @@
1516
using Moryx.Resources.Mqtt.Tests.TestMessages;
1617
using Moryx.Tools;
1718
using MQTTnet;
18-
using MQTTnet.Client;
1919
using MQTTnet.Formatter;
2020
using MQTTnet.Packets;
2121
using MQTTnet.Protocol;
@@ -84,8 +84,7 @@ public void Setup()
8484
private Expression<Func<MqttClientOptions, bool>> CorrectClientOptions()
8585
{
8686
return o => o.ProtocolVersion == _driver.MqttVersion && o.CleanSession == !_driver.ReconnectWithoutCleanSession
87-
&& o.ClientId == $"{System.Net.Dns.GetHostName()}-{_driver.Id}-{_driver.Name}" && (o.ChannelOptions as MqttClientTcpOptions).Server == _driver.BrokerUrl &&
88-
(o.ChannelOptions as MqttClientTcpOptions).Port == _driver.Port;
87+
&& o.ClientId == $"{System.Net.Dns.GetHostName()}-{_driver.Id}-{_driver.Name}";
8988
}
9089

9190
[Test(Description = "Publish Message using Driver")]
@@ -129,7 +128,7 @@ private void SendMessageBoolMqttMessage(MqttApplicationMessage mqttMsg, Cancella
129128
Assert.That(mqttMsg.QualityOfServiceLevel, Is.EqualTo(MqttQualityOfServiceLevel.ExactlyOnce),
130129
"Qos should be ExactlyOnce, but is " + mqttMsg.QualityOfServiceLevel);
131130
var msg = new BoolMqttMessage();
132-
msg.FromBytes(mqttMsg.Payload);
131+
msg.FromBytes(mqttMsg.Payload.ToArray());
133132
Assert.That(msg.Message == MESSAGE_VALUE, "Message should be " + MESSAGE_VALUE + ", but is " + msg.Message);
134133
}
135134

@@ -160,7 +159,7 @@ private void SendMessageBoolIByteSerializableMessage(MqttApplicationMessage sent
160159
Assert.That(sentMsg.QualityOfServiceLevel, Is.EqualTo(MqttQualityOfServiceLevel.ExactlyOnce),
161160
"Qos should be ExactlyOnce, but is " + sentMsg.QualityOfServiceLevel);
162161
var msg = new BoolByteSerializableMessage();
163-
msg.FromBytes(sentMsg.Payload);
162+
msg.FromBytes(sentMsg.Payload.ToArray());
164163
Assert.That(msg.Message == MESSAGE_VALUE, "Message should be " + MESSAGE_VALUE + ", but is " + msg.Message);
165164
}
166165

src/Tests/Moryx.Recources.Mqtt.Tests/TestDriverMqttJsonTopic.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0
33

44
using System;
5+
using System.Buffers;
56
using System.Linq.Expressions;
67
using System.Text;
78
using System.Threading;
@@ -14,7 +15,6 @@
1415
using Moryx.Modules;
1516
using Moryx.Tools;
1617
using MQTTnet;
17-
using MQTTnet.Client;
1818
using MQTTnet.Formatter;
1919
using MQTTnet.Packets;
2020
using Newtonsoft.Json;
@@ -84,8 +84,7 @@ public void Setup()
8484
private Expression<Func<MqttClientOptions, bool>> CorrectClientOptions()
8585
{
8686
return o => o.ProtocolVersion == _driver.MqttVersion && o.CleanSession == !_driver.ReconnectWithoutCleanSession
87-
&& o.ClientId == $"{System.Net.Dns.GetHostName()}-{_driver.Id}-{_driver.Name}" && (o.ChannelOptions as MqttClientTcpOptions).Server == _driver.BrokerUrl &&
88-
(o.ChannelOptions as MqttClientTcpOptions).Port == _driver.Port;
87+
&& o.ClientId == $"{System.Net.Dns.GetHostName()}-{_driver.Id}-{_driver.Name}";
8988
}
9089

9190
[Test(Description = "Publish Json Message using the MqttTopicJson")]
@@ -109,7 +108,8 @@ public void Send_UsingMqttTopicJson_Topic_QOS_Message()
109108
private void CheckSentMessage(MqttApplicationMessage sentMsg, CancellationToken token)
110109
{
111110
var msg = new JsonMessageTest();
112-
var payload = Encoding.UTF8.GetString(sentMsg.Payload, 0, sentMsg.Payload.Length);
111+
var payloadArray = sentMsg.Payload.ToArray();
112+
var payload = Encoding.UTF8.GetString(payloadArray, 0, payloadArray.Length);
113113
if (sentMsg.Topic == _driver.Identifier + _mqttTopicCamel.Identifier)
114114
{
115115
Assert.That(payload.Contains(nameof(JsonMessageTest.Age).ToLower()));

src/Tests/Moryx.Recources.Mqtt.Tests/TestDriverMqttPrimitiveDatatypeTopic.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22
// Licensed under the Apache License, Version 2.0
33

44
using System;
5+
using System.Buffers;
56
using System.Linq.Expressions;
67
using System.Text;
78
using System.Threading;
89
using Microsoft.Extensions.Logging.Abstractions;
910
using Moq;
11+
using Moryx.AbstractionLayer.Resources;
1012
using Moryx.AbstractionLayer.TestTools;
1113
using Moryx.Drivers.Mqtt;
1214
using Moryx.Drivers.Mqtt.MqttTopics;
1315
using Moryx.Logging;
1416
using Moryx.Modules;
1517
using Moryx.Tools;
1618
using MQTTnet;
17-
using MQTTnet.Client;
1819
using MQTTnet.Formatter;
1920
using MQTTnet.Packets;
2021
using MQTTnet.Protocol;
@@ -85,8 +86,7 @@ public void Setup()
8586
private Expression<Func<MqttClientOptions, bool>> CorrectClientOptions()
8687
{
8788
return o => o.ProtocolVersion == _driver.MqttVersion && o.CleanSession == !_driver.ReconnectWithoutCleanSession
88-
&& o.ClientId == $"{System.Net.Dns.GetHostName()}-{_driver.Id}-{_driver.Name}" && (o.ChannelOptions as MqttClientTcpOptions).Server == _driver.BrokerUrl &&
89-
(o.ChannelOptions as MqttClientTcpOptions).Port == _driver.Port;
89+
&& o.ClientId == $"{System.Net.Dns.GetHostName()}-{_driver.Id}-{_driver.Name}";
9090
}
9191

9292
[Test(Description = "Publish int32 Message using the MqttTopicPrimitive")]
@@ -115,7 +115,7 @@ private void SendMessagIntIConvertible(MqttApplicationMessage sentMsg, Cancellat
115115
"Topic should be " + _driver.Identifier + _mqttTopicInt.Identifier + ", but is " + sentMsg.Topic);
116116
Assert.That(sentMsg.QualityOfServiceLevel, Is.EqualTo(MqttQualityOfServiceLevel.ExactlyOnce),
117117
"Qos should be ExactlyOnce, but is " + sentMsg.QualityOfServiceLevel);
118-
var msg = BitConverter.ToInt32(sentMsg.Payload, 0);
118+
var msg = BitConverter.ToInt32(sentMsg.Payload.ToArray(), 0);
119119
Assert.That(msg == MESSAGE_VALUE_INT, "Message should be " + MESSAGE_VALUE_INT + ", but is " + msg);
120120
}
121121

0 commit comments

Comments
 (0)