Skip to content

Commit e1b8312

Browse files
committed
2 parents f3c3b63 + b061aa3 commit e1b8312

File tree

7 files changed

+22
-20
lines changed

7 files changed

+22
-20
lines changed

agrirouter-sdk-dotnet-standard-api/Exception/CouldNotSendMqttMessageException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System;
2-
using MQTTnet.Client.Publishing;
2+
using MQTTnet.Client;
33

44
namespace Agrirouter.Api.Exception
55
{

agrirouter-sdk-dotnet-standard-api/agrirouter-sdk-dotnet-standard-api.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<ItemGroup>
2020
<PackageReference Include="agrirouter-api-protobuf-definitions" Version="1.1.0" />
21-
<PackageReference Include="MQTTnet" Version="3.0.9" />
21+
<PackageReference Include="MQTTnet" Version="4.3.6.1152" />
2222
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
2323
<PackageReference Include="Serilog" Version="2.9.0" />
2424
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />

agrirouter-sdk-dotnet-standard-impl/Service/Common/MqttMessagingService.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using Agrirouter.Api.Service.Parameters;
1010
using MQTTnet;
1111
using MQTTnet.Client;
12-
using MQTTnet.Client.Publishing;
12+
using MQTTnet.Protocol;
1313
using Newtonsoft.Json;
1414

1515
namespace Agrirouter.Impl.Service.Common
@@ -25,7 +25,7 @@ public IMqttClient MqttClient
2525
{
2626
get { return _mqttClient; }
2727
}
28-
28+
2929
/// <summary>
3030
/// Constructor.
3131
/// </summary>
@@ -61,11 +61,13 @@ public async Task<MessagingResult> SendAsync(MessagingParameters messagingParame
6161
var mqttMessage = BuildMqttApplicationMessage(messagingParameters);
6262
var response = await _mqttClient.PublishAsync(mqttMessage, CancellationToken.None);
6363

64-
if (response.ReasonCode != MqttClientPublishReasonCode.Success) {
64+
if (response.ReasonCode != MqttClientPublishReasonCode.Success)
65+
{
6566
throw new CouldNotSendMqttMessageException(response.ReasonCode, response.ReasonString);
6667
}
6768

68-
return new MessagingResultBuilder().WithApplicationMessageId(messagingParameters.ApplicationMessageId).Build();
69+
return new MessagingResultBuilder().WithApplicationMessageId(messagingParameters.ApplicationMessageId)
70+
.Build();
6971
}
7072

7173
private static MqttApplicationMessage BuildMqttApplicationMessage(MessagingParameters messagingParameters)
@@ -78,16 +80,16 @@ private static MqttApplicationMessage BuildMqttApplicationMessage(MessagingParam
7880
};
7981

8082
foreach (var message in messagingParameters.EncodedMessages.Select(encodedMessage =>
81-
new Api.Dto.Messaging.Inner.Message
82-
{Content = encodedMessage, Timestamp = UtcDataService.NowAsUnixTimestamp()}))
83+
new Api.Dto.Messaging.Inner.Message
84+
{ Content = encodedMessage, Timestamp = UtcDataService.NowAsUnixTimestamp() }))
8385
messageRequest.Messages.Add(message);
8486

8587
var messagePayload = JsonConvert.SerializeObject(messageRequest);
8688

8789
var mqttMessage = new MqttApplicationMessageBuilder()
8890
.WithTopic(messagingParameters.OnboardResponse.ConnectionCriteria.Measures)
8991
.WithPayload(messagePayload)
90-
.WithExactlyOnceQoS()
92+
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce)
9193
.WithRetainFlag()
9294
.Build();
9395
return mqttMessage;

agrirouter-sdk-dotnet-standard-test/Helper/MqttConnectionHelper.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Agrirouter.Api.Dto.Onboard;
77
using Agrirouter.Impl.Service.Common;
88
using MQTTnet.Client;
9-
using MQTTnet.Client.Options;
109
using Xunit;
1110

1211
namespace Agrirouter.Test.Helper
@@ -47,7 +46,7 @@ public static async Task ConnectMqttClient(IMqttClient mqttClient, OnboardRespon
4746
.WithTcpServer(onboardResponse.ConnectionCriteria.Host,
4847
int.Parse(onboardResponse.ConnectionCriteria.Port))
4948
.WithTls(tlsParameters)
50-
.WithCommunicationTimeout(TimeSpan.FromSeconds(20))
49+
.WithTimeout(TimeSpan.FromSeconds(20))
5150
.Build();
5251

5352
await mqttClient.ConnectAsync(options);

agrirouter-sdk-dotnet-standard-test/Service/Messaging/Mqtt/CapabilitiesServiceTest.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Agrirouter.Test.Data;
1313
using Agrirouter.Test.Helper;
1414
using MQTTnet;
15-
using MQTTnet.Client;
1615
using Xunit;
1716
using Agrirouter.Api.Dto.Messaging;
1817
using Newtonsoft.Json;
@@ -52,15 +51,17 @@ public async void
5251
var messageReceived = false;
5352
var counter = 0;
5453

55-
mqttClient.UseApplicationMessageReceivedHandler(e =>
54+
mqttClient.ApplicationMessageReceivedAsync += async e =>
5655
{
5756
messageReceived = true;
5857

59-
MessageResponse msg = JsonConvert.DeserializeObject<MessageResponse>(Encoding.UTF8.GetString(e.ApplicationMessage.Payload));
58+
MessageResponse msg =
59+
JsonConvert.DeserializeObject<MessageResponse>(
60+
Encoding.UTF8.GetString(e.ApplicationMessage.Payload));
6061
var decodedMessage = DecodeMessageService.Decode(msg.Command.Message);
6162

6263
Assert.Equal(201, decodedMessage.ResponseEnvelope.ResponseCode);
63-
});
64+
};
6465

6566
while (!messageReceived && counter < 5)
6667
{

agrirouter-sdk-dotnet-standard-test/Service/Messaging/Mqtt/PingServiceTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public async void
3838
var messageReceived = false;
3939
var counter = 0;
4040

41-
mqttClient.UseApplicationMessageReceivedHandler(e =>
41+
mqttClient.ApplicationMessageReceivedAsync += async e =>
4242
{
4343
messageReceived = true;
4444

@@ -47,7 +47,7 @@ public async void
4747
var decodedMessage = DecodeMessageService.Decode(msg.Command.Message);
4848

4949
Assert.Equal(200, decodedMessage.ResponseEnvelope.ResponseCode);
50-
});
50+
};
5151

5252
while (!messageReceived && counter < 5)
5353
{
@@ -90,7 +90,7 @@ public async void
9090
var messageReceived = false;
9191
var counter = 0;
9292

93-
mqttClient.UseApplicationMessageReceivedHandler(e =>
93+
mqttClient.ApplicationMessageReceivedAsync += async e =>
9494
{
9595
messageReceived = true;
9696

@@ -100,7 +100,7 @@ public async void
100100

101101
// your own application should remove the endpoint from your endpoint list/registry now!
102102
Assert.Equal(400, decodedMessage.ResponseEnvelope.ResponseCode);
103-
});
103+
};
104104

105105
while (!messageReceived && counter < 5)
106106
{

agrirouter-sdk-dotnet-standard-test/agrirouter-sdk-dotnet-standard-test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<ItemGroup>
2626
<PackageReference Include="Google.Protobuf" Version="3.20.1" />
2727
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
28-
<PackageReference Include="MQTTnet" Version="3.0.9" />
28+
<PackageReference Include="MQTTnet" Version="4.3.6.1152" />
2929
<PackageReference Include="Serilog.Sinks.Debug" Version="1.0.1" />
3030
<PackageReference Include="xunit" Version="2.4.1" />
3131
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />

0 commit comments

Comments
 (0)