Skip to main content


Instructs the target amqpsession object to close






Important Note Agent AMQP functionality is now deprecated and will shortly become unsupported. Any attempt to interact with imp API amqp objects and methods on unregistered development devices or on production devices will generate a runtime error.

If you are using or intend to use Azure IoTHub, we recommend you make use of MQTT instead of AMQP. Please see our Azure IoT Hub integration for more information.

This method closes an open amqpsession object. Once such an object is closed, it cannot be reopened and reused — instead you should instantiate a new amqpsession object using amqpconnection.opensession().

After the close() call returns, calling isopen() on the target object will return false. However, any variable referencing the target object will not be null until the object goes out of scope, or the variable is nulled manually. As such, isopen() remains the recommended means to determine the state of an amqpsession object.


The following code shows how an open session is closed after a ten-minute delay by calling close() — after first checking that the session is still open by using isopen().


conn <- null;
session <- null;

function amqpConnectionManager(event, errorDetail) {
  // Received an event from the AMQP connection
  if (errorDetail) {
  } else {
    switch(event) {
      case "CONNECTION_OPEN":
        session = conn.opensession(amqpConnectionManager);

        // Close session after 10 minutes if it's not already
        imp.wakeup(600, function() {
          if (session.isopen()) {
            session = null;

// Initiate the connection
local url = "amqps://" + HUB_NAME + "";
conn = amqp.openconnection(url, amqpConnectionManager);