Beispiel #1
0
        async Task SendPendingMessagesAsync(ClientSession session, IMqttChannel <IPacket> channel)
        {
            foreach (var pendingMessage in session.GetPendingMessages())
            {
                var publish = new Publish(pendingMessage.Topic, pendingMessage.QualityOfService,
                                          pendingMessage.Retain, pendingMessage.Duplicated, pendingMessage.PacketId)
                {
                    Payload = pendingMessage.Payload
                };

                if (pendingMessage.Status == PendingMessageStatus.PendingToSend)
                {
                    session.RemovePendingMessage(pendingMessage);
                    sessionRepository.Update(session);

                    await senderFlow.SendPublishAsync(session.Id, publish, channel)
                    .ConfigureAwait(continueOnCapturedContext: false);
                }
                else
                {
                    await senderFlow.SendPublishAsync(session.Id, publish, channel, PendingMessageStatus.PendingToAcknowledge)
                    .ConfigureAwait(continueOnCapturedContext: false);
                }
            }
        }
        async Task SendPendingMessagesAsync(ClientSession session, IMqttChannel <IPacket> channel)
        {
            foreach (PendingMessage pendingMessage in session.GetPendingMessages())
            {
                Publish publish = new Publish(pendingMessage.Topic, pendingMessage.QualityOfService,
                                              pendingMessage.Retain, pendingMessage.Duplicated, pendingMessage.PacketId);

                await _senderFlow
                .SendPublishAsync(session.Id, publish, channel, PendingMessageStatus.PendingToAcknowledge);
            }
        }
        async Task SendPendingMessagesAsync(ClientSession session, IMqttChannel <IPacket> channel)
        {
            foreach (var pendingMessage in session.GetPendingMessages())
            {
                var publish = new Publish(pendingMessage.Topic, pendingMessage.QualityOfService,
                                          pendingMessage.Retain, pendingMessage.Duplicated, pendingMessage.PacketId);

                await senderFlow
                .SendPublishAsync(session.Id, publish, channel, PendingMessageStatus.PendingToAcknowledge)
                .ConfigureAwait(continueOnCapturedContext: false);
            }
        }
Beispiel #4
0
        async Task DispatchAsync(Publish publish, ClientSubscription subscription, bool isWill = false)
        {
            MqttQualityOfService requestedQos = isWill ? publish.QualityOfService : subscription.MaximumQualityOfService;
            MqttQualityOfService supportedQos = configuration.GetSupportedQos(requestedQos);
            bool    retain              = isWill ? publish.Retain : false;
            ushort? packetId            = supportedQos == MqttQualityOfService.AtMostOnce ? null : (ushort?)_packetIdProvider.GetPacketId();
            Publish subscriptionPublish = new Publish(publish.Topic, supportedQos, retain, duplicated: false, packetId: packetId)
            {
                Payload = publish.Payload
            };
            IMqttChannel <IPacket> clientChannel = _connectionProvider.GetConnection(subscription.ClientId);

            await _senderFlow.SendPublishAsync(subscription.ClientId, subscriptionPublish, clientChannel);
        }
Beispiel #5
0
        async Task DispatchAsync(Publish publish, ClientSubscription subscription, bool isWill = false)
        {
            var    requestedQos        = isWill ? publish.QualityOfService : subscription.MaximumQualityOfService;
            var    supportedQos        = configuration.GetSupportedQos(requestedQos);
            var    retain              = isWill ? publish.Retain : false;
            ushort?packetId            = supportedQos == MqttQualityOfService.AtMostOnce ? null : (ushort?)packetIdProvider.GetPacketId();
            var    subscriptionPublish = new Publish(publish.Topic, supportedQos, retain, duplicated: false, packetId: packetId)
            {
                Payload = publish.Payload
            };
            var clientChannel = connectionProvider.GetConnection(subscription.ClientId);

            await senderFlow.SendPublishAsync(subscription.ClientId, subscriptionPublish, clientChannel)
            .ConfigureAwait(continueOnCapturedContext: false);
        }
        async Task SendRetainedMessagesAsync(ClientSubscription subscription, IMqttChannel <IPacket> channel)
        {
            var retainedMessages = retainedRepository.GetAll()
                                   .Where(r => topicEvaluator.Matches(r.Topic, subscription.TopicFilter));

            if (retainedMessages != null)
            {
                foreach (var retainedMessage in retainedMessages)
                {
                    ushort?packetId = subscription.MaximumQualityOfService == MqttQualityOfService.AtMostOnce ?
                                      null : (ushort?)packetIdProvider.GetPacketId();
                    var publish = new Publish(retainedMessage.Topic, subscription.MaximumQualityOfService,
                                              retain: true, duplicated: false, packetId: packetId)
                    {
                        Payload = retainedMessage.Payload
                    };

                    await senderFlow.SendPublishAsync(subscription.ClientId, publish, channel)
                    .ConfigureAwait(continueOnCapturedContext: false);
                }
            }
        }
Beispiel #7
0
        async Task SendRetainedMessagesAsync(ClientSubscription subscription, IMqttChannel <IPacket> channel)
        {
            IEnumerable <RetainedMessage> retainedMessages = _retainedRepository
                                                             .ReadAll()
                                                             .Where(r => _topicEvaluator.Matches(topicName: r.Id, topicFilter: subscription.TopicFilter));

            if (retainedMessages != null)
            {
                foreach (RetainedMessage retainedMessage in retainedMessages)
                {
                    ushort?packetId = subscription.MaximumQualityOfService == MqttQualityOfService.AtMostOnce ?
                                      null : (ushort?)_packetIdProvider.GetPacketId();
                    Publish publish = new Publish(topic: retainedMessage.Id,
                                                  qualityOfService: subscription.MaximumQualityOfService,
                                                  retain: true, duplicated: false, packetId: packetId)
                    {
                        Payload = retainedMessage.Payload
                    };

                    await _senderFlow.SendPublishAsync(subscription.ClientId, publish, channel);
                }
            }
        }