title: Spring Mqtt: MqttPahoMessageDrivenChannelAdapter - Lost connection:Connection lost; retrying
body: <p>We are seeing an exception as mentioned in this topic title when trying to work on an Spring MQTT integration.</p>
  
  <p>The setup details are as below:
  1) We have two different message adapters: message-driven-channel-adapter and outbound-channel-adapter. Both have unique clientIDs</p>
  
  <p>2) A desktop application is used as an Mqtt client to publish some messages which are handled by message-driven-channel-adapter. Sample code is as below:</p>
  
  <pre><code>ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
              DefaultMqttPahoClientFactory mqttClientFactory = (DefaultMqttPahoClientFactory) ac.getBean("clientFactory");
              MqttClient gatewayClient = mqttClientFactory.getClientInstance("tcp://abc.com:1883", "STCLP014CI021CLIENT1");
              String test = "this is test"
              gatewayClient.connect();
              MqttMessage message = new MqttMessage(test.getBytes());
              message.setQos(1);
              gatewayClient.publish("store/entity/mpg/zmesg/fromdevice/014/00021/eco/pos/a56f4302004b1200/1420221417963/2ce6f45f-97a6-49d2-91e5-640effcfa651/192.168.10.70", message);
              gatewayClient.disconnect();
  </code></pre>
  
  <p>3) A listner bean configured for message-driven-channel-adapter processes the incoming messages and also publishes a response to the outbound-channel-adapter's channel. </p>
  
  <p>The sample code is as below:</p>
  
  <pre><code>    public void processMessage(String message)
      {
  
  ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
              System.out.println("message received  " + message);
  
  String response = "response message";
  
  MessageChannel responseChannel = (MessageChannel) ac.getBean("mpgResponseChannel");
              responseChannel.send(new GenericMessage&lt;String&gt;(response));   
  }
  </code></pre>
  
  <p>the above code publishes the message successfully but disconnects the 'inbound'  message-driven-channel-adapter and we see a continuous stacktrace as below on the console:</p>
  
  <pre><code>11:09:33.675 [MQTT Rec: STCLP014CI021CLIENT3] ERROR o.s.i.m.i.MqttPahoMessageDrivenChannelAdapter - Lost connection:Connection lost; retrying...
  11:09:33.787 [MQTT Rec: STCLP014CI021CLIENT3] ERROR o.s.i.m.i.MqttPahoMessageDrivenChannelAdapter - Lost connection:Connection lost; retrying...
  11:09:33.850 [MQTT Rec: STCLP014CI021CLIENT3] ERROR o.s.i.m.i.MqttPahoMessageDrivenChannelAdapter - Lost connection:Connection lost; retrying...
  11:09:33.959 [MQTT Rec: STCLP014CI021CLIENT3] ERROR o.s.i.m.i.MqttPahoMessageDrivenChannelAdapter - Lost connection:Connection lost; retrying...
  11:09:34.021 [MQTT Rec: STCLP014CI021CLIENT3] ERROR o.s.i.m.i.MqttPahoMessageDrivenChannelAdapter - Lost connection:Connection lost; retrying...
  </code></pre>
  
  <p>Can someone please advise on the above?</p>
  
  <p>Is there a way to make sure that the inbound adapter does not disconnect after a message is published to the outbound adapter?</p>
  
  <p>regards.</p>