protected boolean connectToRabbitMQ(final String userName,final String password){
  if ((mChannel != null) && mChannel.isOpen()) {
    return true;
  }
  try {
    final ConnectionFactory connectionFactory=new ConnectionFactory();
    connectionFactory.setHost(mServer);
    connectionFactory.setUsername(userName);
    connectionFactory.setPassword(password);
    connectionFactory.setVirtualHost(mVirtualHost);
    connectionFactory.setPort(mPort);
    connectionFactory.setRequestedHeartbeat(AppConstants.HEART_BEAT);
    Logger.d(TAG,AppConstants.HEART_BEAT + "");
    mConnection=connectionFactory.newConnection();
    mChannel=mConnection.createChannel();
    mChannel.exchangeDeclare(mExchange,mExchangeType.key);
    return true;
  }
 catch (  final Exception e) {
    e.printStackTrace();
    return false;
  }
}

protected boolean connectToRabbitMQ ( final String userName , final String password ) { if ( ( mChannel != null ) && mChannel . isOpen ( ) ) { return true ; } try { final ConnectionFactory connectionFactory = new ConnectionFactory ( ) ; connectionFactory . setHost ( mServer ) ; connectionFactory . setUsername ( userName ) ; connectionFactory . setPassword ( password ) ; connectionFactory . setVirtualHost ( mVirtualHost ) ; connectionFactory . setPort ( mPort ) ; connectionFactory . setRequestedHeartbeat ( AppConstants . HEART_BEAT ) ; Logger . d ( TAG , AppConstants . HEART_BEAT + "" ) ; mConnection = connectionFactory . newConnection ( ) ; mChannel = mConnection . createChannel ( ) ; mChannel . exchangeDeclare ( mExchange , mExchangeType . key ) ; return true ; } catch ( final Exception e ) { e . printStackTrace ( ) ; return false ; } }
connect to the broker and create the exchange
