title: MQTT Application connect with two brokers using single client app/library
body: <p>I am using <a href="https://eclipse.org/paho/clients/java/" rel="nofollow noreferrer">MQTT Eclipse Paho</a> Java Library (JAR) for connection to a MQTT broker.  </p>
  
  <p>But I want to connect with two brokers using the same library. I have implemented code to connect with two brokers, it does connect but problem is that after sometime connection randomly disconnects (Either one of the connection).  </p>
  
  <p>So what is the best way to connect with two MQTT Brokers using one MQTT client library. </p>
  
  <p><strong>Updated</strong></p>
  
  <p>My code for connection looks like below:   </p>
  
  <pre><code>import org.eclipse.paho.client.mqttv3.MqttClient;
  Class com.test.A
  {
      MqttClient mMqttClient;
      A()
      {
           mMqttClient = new MqttClient("broker_url_1", "Client1", persistence);
  
           // Create MQTT connection options 
           MqttConnectOptions connOpts = new MqttConnectOptions();
           connOpts.setCleanSession(true); // Create new clear session
  
           mMqttClient.connect(connOpts);
      }
  }
  
  import org.eclipse.paho.client.mqttv3.MqttClient;
  Class com.test.B
  {
      MqttClient mMqttClient;
      B()
      {
           mMqttClient = new MqttClient("broker_url_2", "Client2", persistence);
  
           // Create MQTT connection options 
           MqttConnectOptions connOpts = new MqttConnectOptions();
           connOpts.setCleanSession(true); // Create new clear session
  
           mMqttClient.connect(connOpts);
      }    
  }
  </code></pre>
  
  <p>Error That I am getting after connection lots <code>connectionLost: cause: Connection lost</code>  </p>