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

Throw exception if we failed to send an MQTT message #97

Merged
merged 1 commit into from
Nov 14, 2021
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 @@ -20,8 +20,8 @@ public CouldNotSendHttpMessageException(HttpStatusCode statusCode, string errorM
ErrorMessage = errorMessage;
}

private HttpStatusCode StatusCode { get; }
public HttpStatusCode StatusCode { get; }

private string ErrorMessage { get; }
public string ErrorMessage { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Agrirouter.Api.Service.Parameters;
using MQTTnet;
using MQTTnet.Client;
using MQTTnet.Client.Publishing;
using Newtonsoft.Json;

namespace Agrirouter.Impl.Service.Common
Expand Down Expand Up @@ -53,7 +54,11 @@ public MessagingResult Send(MessagingParameters messagingParameters)
public async Task<MessagingResult> SendAsync(MessagingParameters messagingParameters)
{
var mqttMessage = BuildMqttApplicationMessage(messagingParameters);
await _mqttClient.PublishAsync(mqttMessage, CancellationToken.None);
var response = await _mqttClient.PublishAsync(mqttMessage, CancellationToken.None);

if (response.ReasonCode != MqttClientPublishReasonCode.Success) {
throw new CouldNotSendMqttMessageException(response.ReasonCode, response.ReasonString);
}

return new MessagingResultBuilder().WithApplicationMessageId(messagingParameters.ApplicationMessageId).Build();
}
Expand Down