Esempio n. 1
0
        async Task DispatchAsync(Publish publish, string clientId, bool isWill = false)
        {
            System.Collections.Generic.IEnumerable <ClientSubscription> subscriptions = sessionRepository
                                                                                        .ReadAll().ToList()
                                                                                        .SelectMany(s => s.GetSubscriptions())
                                                                                        .Where(x => topicEvaluator.Matches(publish.Topic, x.TopicFilter));

            if (!subscriptions.Any())
            {
                _tracer.Verbose(ServerProperties.ServerPublishReceiverFlow_TopicNotSubscribed(publish.Topic, clientId));

                _undeliveredMessagesListener.OnNext(new MqttUndeliveredMessage {
                    SenderId = clientId, Message = new MqttApplicationMessage(publish.Topic, publish.Payload)
                });
            }
            else
            {
                foreach (ClientSubscription subscription in subscriptions)
                {
                    await DispatchAsync(publish, subscription, isWill);
                }
            }
        }