Monitoring the Connection

    For example, the client library may provide a mechanism to get the connection’s current status:

    Java

    1. System.out.println("The Connection is: " + nc.getStatus());
    2. nc.close();
    3. System.out.println("The Connection is: " + nc.getStatus());

    Python

    1. nc = NATS()
    2. )
    3. # Do something with the connection.
    4. print("The connection is connected?", nc.is_connected)
    5. while True:
    6. if nc.is_reconnecting:
    7. await asyncio.sleep(1)
    8. await nc.close()
    9. print("The connection is closed?", nc.is_closed)

    TypeScript

    1. if(nc.isClosed()) {
    2. t.log('the client is closed');
    3. } else {