public static void connectAsynchronously ( Options options , boolean reconnectOnConnect ) throws InterruptedException { if ( options . getConnectionListener ( ) == null ) { throw new IllegalArgumentException ( "Connection Listener required in connectAsynchronously" ) ; } Thread t = new Thread ( ( ) -> { try { NatsImpl . createConnection ( options , reconnectOnConnect ) ; } catch ( Exception ex ) { if ( options . getErrorListener ( ) != null ) { options . getErrorListener ( ) . exceptionOccurred ( null , ex ) ; } } } ) ; t . setName ( "NATS - async connection" ) ; t . start ( ) ; }
Try to connect in another thread a connection listener is required to get the connection .