title: MQTT and SpringBoot Integration Connection Lost
body: <p>I currently have an API in SpringBoot and I would like to add an MQTT client to subscribe to one or more topics.
  I tried several Paho,Hive clients, without success, I'm currently on the default MQTT of SpringBoot which uses Paho but I can't get it to work even with the basic configuration.
  I get a &quot;Connection Lost&quot; error as soon as I launch the application...
  Can you tell me a fix or something else that would work. Thanks!
  <a href="https://i.stack.imgur.com/KZld6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KZld6.png" alt="Mosquitto is running on windows for testing" /></a></p>
  <p>Maven :</p>
  <pre><code>        &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.integration&lt;/groupId&gt;
              &lt;artifactId&gt;spring-integration-mqtt&lt;/artifactId&gt;           
          &lt;/dependency&gt;
  </code></pre>
  <pre><code>....
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.context.annotation.Bean;
  import org.springframework.integration.annotation.ServiceActivator;
  import org.springframework.integration.channel.DirectChannel;
  import org.springframework.integration.core.MessageProducer;
  import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
  import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter;
  import org.springframework.messaging.Message;
  import org.springframework.messaging.MessageChannel;
  import org.springframework.messaging.MessageHandler;
  import org.springframework.messaging.MessagingException;
  
  import lombok.extern.slf4j.Slf4j;
  import springfox.documentation.swagger2.annotations.EnableSwagger2;
  
  @Slf4j
  @SpringBootApplication
  @EnableSwagger2
  public class MainApiSpring {
  
      public static void main(String[] args) {
  
          SpringApplication.run(MainApiSpring.class, args);
          log.trace(&quot;L'application a correctement été démarrée.&quot;);
  
      }
  
      @Bean
      public MessageChannel mqttInputChannel() {
          return new DirectChannel();
      }
  
      @Bean
      public MessageProducer inbound() {
          MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(&quot;tcp://localhost:1883&quot;,
                  &quot;test/topic&quot;);
          adapter.setCompletionTimeout(5000);
          adapter.setConverter(new DefaultPahoMessageConverter());
          adapter.setQos(1);
  
          adapter.setOutputChannel(mqttInputChannel());
          return adapter;
      }
  
      @Bean
      @ServiceActivator(inputChannel = &quot;mqttInputChannel&quot;)
      public MessageHandler handler() {
          return new MessageHandler() {
  
              @Override
              public void handleMessage(Message&lt;?&gt; message) throws MessagingException {
                  System.out.println(message.getPayload());
              }
  
          };
      }
  }
  </code></pre>
  <p>The error on run :</p>
  <pre><code>2020-09-04 10:31:39.099 ERROR 4244 --- [           main] .m.i.MqttPahoMessageDrivenChannelAdapter : Exception while connecting and subscribing, retrying
  
  org.eclipse.paho.client.mqttv3.MqttException: Connexion perdue
      at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:197) ~[org.eclipse.paho.client.mqttv3-1.2.4.jar:na]
      at java.base/java.lang.Thread.run(Thread.java:830) ~[na:na]
  Caused by: java.io.EOFException: null
      at java.base/java.io.DataInputStream.readByte(DataInputStream.java:272) ~[na:na]
      at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:92) ~[org.eclipse.paho.client.mqttv3-1.2.4.jar:na]
      at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:137) ~[org.eclipse.paho.client.mqttv3-1.2.4.jar:na]
      ... 1 common frames omitted
  </code></pre>
  <p><a href="https://i.stack.imgur.com/G8bTg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G8bTg.png" alt="More log" /></a></p>