deleteConnection method

Future<void> deleteConnection({
  1. required String clientId,
  2. bool? cleanSession,
  3. bool? preventWillMessage,
})

Disconnects a connected MQTT client from Amazon Web Services IoT Core. When you disconnect a client, Amazon Web Services IoT Core closes the client's network connection and optionally cleans the session state.

Requires permission to access the DeleteConnection action.

May throw ForbiddenException. May throw InternalFailureException. May throw InvalidRequestException. May throw ResourceNotFoundException. May throw ThrottlingException.

Parameter clientId : The unique identifier of the MQTT client to disconnect. The client ID can't start with a dollar sign ($).

MQTT client IDs must be URL encoded (percent-encoded) when they contain characters that are not valid in HTTP requests, such as spaces, forward slashes (/), and UTF-8 characters.

Parameter cleanSession : Specifies whether to remove the client's persistent session state when disconnecting. Set to TRUE to delete all session information, including subscriptions and queued messages. Set to FALSE to preserve the session state for persistent sessions. For clean sessions this parameter will be ignored. By default, this is set to FALSE (preserves the session state).

Parameter preventWillMessage : Controls if Amazon Web Services IoT Core publishes the client's Last Will and Testament (LWT) message upon disconnection. Set to TRUE to prevent publishing the LWT message. Set to FALSE to ensure that LWT is published. By default, this is set to FALSE (LWT message is published).

Implementation

Future<void> deleteConnection({
  required String clientId,
  bool? cleanSession,
  bool? preventWillMessage,
}) async {
  final $query = <String, List<String>>{
    if (cleanSession != null) 'cleanSession': [cleanSession.toString()],
    if (preventWillMessage != null)
      'preventWillMessage': [preventWillMessage.toString()],
  };
  await _protocol.send(
    payload: null,
    method: 'DELETE',
    requestUri: '/connections/${Uri.encodeComponent(clientId)}',
    queryParams: $query,
    exceptionFnMap: _exceptionFns,
  );
}