Exemplo n.º 1
0
        async void ShutdownOnReceiveError(string exception)
        {
            this.publishPubAckProcessor.Abort();
            foreach (var publishProcessor in this.publishProcessors)
            {
                publishProcessor.Value.Abort();
            }
            this.publishPubRecProcessor.Abort();
            this.pubRelPubCompProcessor.Abort();

            IMqttMessagingBridge bridge = this.messagingBridge;

            if (bridge != null)
            {
                this.messagingBridge = null;
                try
                {
                    await bridge.DisposeAsync();
                }
                catch (Exception ex)
                {
                    CommonEventSource.Log.Info("Failed to close IoT Hub Client cleanly.", ex.ToString());
                }
            }
            ShutdownOnError(this.capturedContext, "Receive", exception);
        }
Exemplo n.º 2
0
        async void CloseIotHubConnection(IChannelHandlerContext context, PublishPacket will)
        {
            if (!this.ConnectedToHub)
            {
                // closure happened before IoT Hub connection was established or it was initiated due to disconnect
                return;
            }

            try
            {
                foreach (var publishProcessor in this.publishProcessors)
                {
                    publishProcessor.Value.Complete();
                }
                this.publishPubAckProcessor.Complete();
                this.publishPubRecProcessor.Complete();
                this.pubRelPubCompProcessor.Complete();
                await Task.WhenAll(
                    this.CompletePublishAsync(context, will),
                    this.publishPubAckProcessor.Completion,
                    this.publishPubRecProcessor.Completion,
                    this.pubRelPubCompProcessor.Completion);

                IMqttMessagingBridge hub = this.messagingBridge;
                this.messagingBridge = null;
                await hub.DisposeAsync();
            }
            catch (Exception ex)
            {
                CommonEventSource.Log.Info("Failed to close IoT Hub Client cleanly.", ex.ToString());
            }
        }