private void RegisterMqtt(Mqtt_Settings settings)
        {
            var factory = new MqttFactory();

            Client        = factory.CreateMqttClient();
            ClientOptions = new MqttClientOptionsBuilder()
                            .WithClientId((settings.ClientId + "S"))
                            .WithTcpServer(settings.Host)
                            .Build();

            Client.ConnectedHandler = new MqttClientConnectedHandlerDelegate(async e => {
                await Client.PublishAsync(PublishOptions);
                DisconnectMqtt();
            });
        }
        private void RegisterMqtt(Mqtt_Settings settings)
        {
            Console.WriteLine($"Sub started in {settings.ClientId}");
            var factory = new MqttFactory();

            Client        = factory.CreateMqttClient();
            ClientOptions = new MqttClientOptionsBuilder()
                            .WithClientId(settings.ClientId)
                            .WithTcpServer(settings.Host)
                            .Build();

            var PublishOptions = new MqttApplicationMessageBuilder()
                                 .WithTopic("MyTopic")
                                 .WithPayload("Hello World")
                                 .WithExactlyOnceQoS()
                                 .WithRetainFlag()
                                 .Build();

            Client.ConnectedHandler = new MqttClientConnectedHandlerDelegate(e => {
                Client.SubscribeAsync(new TopicFilterBuilder().WithTopic(settings.SuscribeTopic).Build());
            });
        }
 public MqttClient(IApplicationLifetime appLifetime, IServiceProvider serviceProvider, Mqtt_Settings settings)
 {
     _appLifetime     = appLifetime;
     _serviceProvider = serviceProvider;
     RegisterMqtt(settings);
 }