diff --git a/.github/workflows/ReleaseNotes.md b/.github/workflows/ReleaseNotes.md index 85846c97..ea58c283 100644 --- a/.github/workflows/ReleaseNotes.md +++ b/.github/workflows/ReleaseNotes.md @@ -3,6 +3,7 @@ * [Client] Added support for passing MQTT v5 options (User properties etc.) for disconnects. * [Client] An internal exception is no longer caught silently when calling _DisconnectAsync_ to indicate that the disconnect is not clean (BREAKING CHANGE). * [Client] MQTTv5 features are now checked and an exception is thrown if they are used when using protocol version 3.1.1 and lower. These checks can be disabled in client options. (BREAKING CHANGE!). +* [ManagedClient] Exposed added and removed topics in _ManagedProcessFailedEventArgs_ (#1678, thanks to @scottbrogden-iheartmedia). * [Client] Added support for disabling packet fragmentation (required for i.e. AWS, #1690, thanks to @logicaloud). * [Server] Exposed MQTT v5 sent properties from the affected client in _ClientDisconnectedAsync_ event. * [Server] Fixed wrong client ID passed to _InterceptingUnsubscriptionEventArgs_ (#1631, thanks to @ghord). diff --git a/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs b/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs index 0c04c663..3690be8c 100644 --- a/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs +++ b/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs @@ -353,13 +353,13 @@ namespace MQTTnet.Extensions.ManagedClient return remainingTime < TimeSpan.Zero ? TimeSpan.Zero : remainingTime; } - async Task HandleSubscriptionExceptionAsync(Exception exception) + async Task HandleSubscriptionExceptionAsync(Exception exception, List addedSubscriptions, List removedSubscriptions) { _logger.Warning(exception, "Synchronizing subscriptions failed."); if (_synchronizingSubscriptionsFailedEvent.HasHandlers) { - await _synchronizingSubscriptionsFailedEvent.InvokeAsync(new ManagedProcessFailedEventArgs(exception)).ConfigureAwait(false); + await _synchronizingSubscriptionsFailedEvent.InvokeAsync(new ManagedProcessFailedEventArgs(exception, addedSubscriptions, removedSubscriptions)).ConfigureAwait(false); } } @@ -457,11 +457,13 @@ namespace MQTTnet.Extensions.ManagedClient { _logger.Info("Publishing subscriptions at reconnect"); + List topicFilters = null; + try { if (_reconnectSubscriptions.Any()) { - var topicFilters = new List(); + topicFilters = new List(); foreach (var sub in _reconnectSubscriptions) { @@ -479,7 +481,7 @@ namespace MQTTnet.Extensions.ManagedClient } catch (Exception exception) { - await HandleSubscriptionExceptionAsync(exception).ConfigureAwait(false); + await HandleSubscriptionExceptionAsync(exception, topicFilters, null).ConfigureAwait(false); } } @@ -591,6 +593,9 @@ namespace MQTTnet.Extensions.ManagedClient } await InternalClient.UnsubscribeAsync(unsubscribeOptionsBuilder.Build()).ConfigureAwait(false); + + //clear because these worked, maybe the subscribe below will fail, only report those + removedSubscriptions.Clear(); } if (addedSubscriptions != null && addedSubscriptions.Any()) @@ -607,7 +612,7 @@ namespace MQTTnet.Extensions.ManagedClient } catch (Exception exception) { - await HandleSubscriptionExceptionAsync(exception).ConfigureAwait(false); + await HandleSubscriptionExceptionAsync(exception, addedSubscriptions, removedSubscriptions).ConfigureAwait(false); } } diff --git a/Source/MQTTnet.Extensions.ManagedClient/ManagedProcessFailedEventArgs.cs b/Source/MQTTnet.Extensions.ManagedClient/ManagedProcessFailedEventArgs.cs index 73eee45e..937c7d83 100644 --- a/Source/MQTTnet.Extensions.ManagedClient/ManagedProcessFailedEventArgs.cs +++ b/Source/MQTTnet.Extensions.ManagedClient/ManagedProcessFailedEventArgs.cs @@ -2,17 +2,33 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using MQTTnet.Packets; using System; +using System.Collections.Generic; +using System.Linq; namespace MQTTnet.Extensions.ManagedClient { public class ManagedProcessFailedEventArgs : EventArgs { - public ManagedProcessFailedEventArgs(Exception exception) + public ManagedProcessFailedEventArgs(Exception exception, List addedSubscriptions, List removedSubscriptions) { Exception = exception ?? throw new ArgumentNullException(nameof(exception)); + + if (addedSubscriptions != null) + { + AddedSubscriptions = new List(addedSubscriptions.Select(item => item.Topic)); + } + + if (removedSubscriptions != null) + { + RemovedSubscriptions = new List(removedSubscriptions); + } } public Exception Exception { get; } + + public List AddedSubscriptions { get; } + public List RemovedSubscriptions { get; } } } \ No newline at end of file