diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs index c0e9e0c..91e5b8b 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs @@ -145,16 +145,16 @@ namespace MQTTnet.Server PendingMessagesQueue.Enqueue(publishPacket); } - public Task SubscribeAsync(IList topicFilters) + public async Task SubscribeAsync(IList topicFilters) { if (topicFilters == null) throw new ArgumentNullException(nameof(topicFilters)); - var response = SubscriptionsManager.SubscribeAsync(new MqttSubscribePacket + await SubscriptionsManager.SubscribeAsync(new MqttSubscribePacket { TopicFilters = topicFilters - }); + }).ConfigureAwait(false); - return response; + await EnqueueSubscribedRetainedMessagesAsync(topicFilters).ConfigureAwait(false); } public Task UnsubscribeAsync(IList topicFilters) @@ -270,7 +270,7 @@ namespace MQTTnet.Server await StopAsync().ConfigureAwait(false); } - await EnqueueSubscribedRetainedMessagesAsync(subscribePacket).ConfigureAwait(false); + await EnqueueSubscribedRetainedMessagesAsync(subscribePacket.TopicFilters).ConfigureAwait(false); } private async Task HandleIncomingUnsubscribePacketAsync(IMqttChannelAdapter adapter, MqttUnsubscribePacket unsubscribePacket, CancellationToken cancellationToken) @@ -279,12 +279,12 @@ namespace MQTTnet.Server await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, unsubscribeResult); } - private async Task EnqueueSubscribedRetainedMessagesAsync(MqttSubscribePacket subscribePacket) + private async Task EnqueueSubscribedRetainedMessagesAsync(ICollection topicFilters) { - var retainedMessages = await _retainedMessagesManager.GetSubscribedMessagesAsync(subscribePacket); - foreach (var publishPacket in retainedMessages) + var retainedMessages = await _retainedMessagesManager.GetSubscribedMessagesAsync(topicFilters); + foreach (var applicationMessage in retainedMessages) { - await EnqueueApplicationMessageAsync(publishPacket); + await EnqueueApplicationMessageAsync(applicationMessage).ConfigureAwait(false); } }