Class MqttConnectionConfig

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public final class MqttConnectionConfig
    extends CrtResource
    Encapsulates all per-mqtt-connection configuration
    • Constructor Detail

      • MqttConnectionConfig

        public MqttConnectionConfig()
    • Method Detail

      • setConnectionCallbacks

        public void setConnectionCallbacks​(MqttClientConnectionEvents connectionCallbacks)
        Configures the connection-related callbacks for a connection
        Parameters:
        connectionCallbacks - connection event callbacks to use
      • getConnectionCallbacks

        public MqttClientConnectionEvents getConnectionCallbacks()
        Queries the connection-related callbacks for a connection
        Returns:
        the connection event callbacks to use
      • setClientId

        public void setClientId​(java.lang.String clientId)
        Configures the client_id to use with a connection
        Parameters:
        clientId - The client id for a connection. Needs to be unique across all devices/clients.this.credentialsProvider
      • getClientId

        public java.lang.String getClientId()
        Queries the client_id being used by a connection
        Returns:
        The client id for a connection.
      • setEndpoint

        public void setEndpoint​(java.lang.String endpoint)
        Configures the IoT endpoint for a connection
        Parameters:
        endpoint - The IoT endpoint to connect to
      • getEndpoint

        public java.lang.String getEndpoint()
        Queries the IoT endpoint used by a connection
        Returns:
        The IoT endpoint used by a connection
      • setPort

        public void setPort​(int port)
        Configures the port to connect to.
        Parameters:
        port - The port to connect to. Usually 8883 for MQTT, or 443 for websockets
      • getPort

        public int getPort()
        Queries the port to connect to.
        Returns:
        The port to connect to
      • setSocketOptions

        public void setSocketOptions​(SocketOptions socketOptions)
        Configures the common settings to use for a connection's socket
        Parameters:
        socketOptions - The socket settings
      • getSocketOptions

        public SocketOptions getSocketOptions()
        Queries the common settings to use for a connection's socket
        Returns:
        The socket settings
      • setCleanSession

        public void setCleanSession​(boolean cleanSession)
        Configures whether or not the service should try to resume prior subscriptions, if it has any
        Parameters:
        cleanSession - true if the session should drop prior subscriptions when a connection is established, false to resume the session
      • getCleanSession

        public boolean getCleanSession()
        Queries whether or not the service should try to resume prior subscriptions, if it has any
        Returns:
        true if the session should drop prior subscriptions when a connection is established, false to resume the session
      • setKeepAliveMs

        @Deprecated
        public void setKeepAliveMs​(int keepAliveMs)
        Deprecated.
        Configures MQTT keep-alive via PING messages. Note that this is not TCP keepalive. Please use setKeepAliveSecs instead.
        Parameters:
        keepAliveMs - How often in milliseconds to send an MQTT PING message to the service to keep a connection alive
      • getKeepAliveMs

        @Deprecated
        public int getKeepAliveMs()
        Deprecated.
        Queries the MQTT keep-alive via PING messages. Please use getKeepAliveSecs instead.
        Returns:
        How often in milliseconds to send an MQTT PING message to the service to keep a connection alive
      • setKeepAliveSecs

        public void setKeepAliveSecs​(int keepAliveSecs)
        Configures MQTT keep-alive via PING messages. Note that this is not TCP keepalive. Note: AWS IoT Core only allows 30-1200 Secs. Anything larger than 65535 will be capped.
        Parameters:
        keepAliveSecs - How often in seconds to send an MQTT PING message to the service to keep a connection alive
      • getKeepAliveSecs

        public int getKeepAliveSecs()
        Queries the MQTT keep-alive via PING messages.
        Returns:
        How often in seconds to send an MQTT PING message to the service to keep a connection alive
      • setPingTimeoutMs

        public void setPingTimeoutMs​(int pingTimeoutMs)
        Configures ping timeout value. If a response is not received within this interval, the connection will be reestablished.
        Parameters:
        pingTimeoutMs - How long to wait for a ping response (in milliseconds) before resetting the connection
      • getPingTimeoutMs

        public int getPingTimeoutMs()
        Queries ping timeout value. If a response is not received within this interval, the connection will be reestablished.
        Returns:
        How long to wait for a ping response before resetting the connection
      • setReconnectTimeoutSecs

        public void setReconnectTimeoutSecs​(long minTimeoutSecs,
                                            long maxTimeoutSecs)
        Configures the minimum and maximum reconnect timeouts. The time between reconnect attempts will start at min and multiply by 2 until max is reached. Default value for min is 1, for max 128. Set either one to zero will use the default setting.
        Parameters:
        minTimeoutSecs - The timeout to start with
        maxTimeoutSecs - The highest allowable wait time between reconnect attempts
      • getMinReconnectTimeoutSecs

        public long getMinReconnectTimeoutSecs()
        Return the minimum reconnect timeout.
        Returns:
        The timeout to start with
      • getMaxReconnectTimeoutSecs

        public long getMaxReconnectTimeoutSecs()
        Return the maximum reconnect timeout.
        Returns:
        The highest allowable wait time between reconnect attempts
      • setProtocolOperationTimeoutMs

        public void setProtocolOperationTimeoutMs​(int protocolOperationTimeoutMs)
        Configures timeout value for requests that response is required on healthy connection. If a response is not received within this interval, the request will fail as server not receiving it. Applied to publish (QoS>0) and unsubscribe
        Parameters:
        protocolOperationTimeoutMs - How long to wait for a request response (in milliseconds) before failing
      • getProtocolOperationTimeoutMs

        public int getProtocolOperationTimeoutMs()
        Queries timeout value for requests that response is required on healthy connection. If a response is not received within this interval, the request will fail as server not receiving it. Applied to publish (QoS>0) and unsubscribe
        Returns:
        How long to wait for a request response (in milliseconds) before failing
      • setMqttClient

        public void setMqttClient​(MqttClient mqttClient)
        Configures the mqtt client to use for a connection
        Parameters:
        mqttClient - the mqtt client to use
      • getMqttClient

        public MqttClient getMqttClient()
        Queries the mqtt client to use for a connection
        Returns:
        the mqtt client to use
      • setMqtt5Client

        public void setMqtt5Client​(Mqtt5Client mqtt5Client)
        Configures the mqtt5 client to use for a connection
        Parameters:
        mqtt5Client - the mqtt client to use
      • getMqtt5Client

        public Mqtt5Client getMqtt5Client()
        Queries the mqtt5 client to use for a connection
        Returns:
        the mqtt5 client to use
      • setLogin

        public void setLogin​(java.lang.String user,
                             java.lang.String pass)
                      throws MqttException
        Sets the login credentials for a connection.
        Parameters:
        user - Login username
        pass - Login password
        Throws:
        MqttException
      • setUsername

        public void setUsername​(java.lang.String username)
        Configures the username to use as part of the CONNECT attempt
        Parameters:
        username - username to use for the mqtt connect operation
      • getUsername

        public java.lang.String getUsername()
        Queries the username to use as part of the CONNECT attempt
        Returns:
        username to use for the mqtt connect operation
      • setPassword

        public void setPassword​(java.lang.String password)
        Configures the password to use as part of the CONNECT attempt
        Parameters:
        password - password to use for the mqtt connect operation
      • getPassword

        public java.lang.String getPassword()
        Queries the password to use as part of the CONNECT attempt
        Returns:
        password to use for the mqtt connect operation
      • setWillMessage

        public void setWillMessage​(MqttMessage willMessage)
        Configures the last will and testament message to be delivered to a topic when a connection disconnects
        Parameters:
        willMessage - the message to publish as the will
      • getWillMessage

        public MqttMessage getWillMessage()
        Queries the last will and testament message to be delivered to a topic when a connection disconnects
        Returns:
        the message to publish as the will
      • setWillQos

        @Deprecated
        public void setWillQos​(QualityOfService qos)
        Deprecated.
        Set QoS directly on the will's MqttMessage.
        Parameters:
        qos - Quality of Service
      • getWillQos

        @Deprecated
        public QualityOfService getWillQos()
        Deprecated.
        Query QoS directly from the will's MqttMessage.
        Returns:
        Quality of Service
      • setWillRetain

        @Deprecated
        public void setWillRetain​(boolean retain)
        Deprecated.
        Set retain directly on the will's MqttMessage.
        Parameters:
        retain - whether will's should be sent with retain property set
      • getWillRetain

        @Deprecated
        public boolean getWillRetain()
        Deprecated.
        Query retain directly from the will's MqttMessage.
        Returns:
        whether will will be sent with retain property set
      • setUseWebsockets

        public void setUseWebsockets​(boolean useWebsockets)
        Configures whether or not to use websockets for the mqtt connection
        Parameters:
        useWebsockets - whether or not to use websockets
      • getUseWebsockets

        public boolean getUseWebsockets()
        Queries whether or not to use websockets for the mqtt connection
        Returns:
        whether or not to use websockets
      • setWebsocketProxyOptions

        public void setWebsocketProxyOptions​(HttpProxyOptions proxyOptions)
        Deprecated.
        use setHttpProxyOptions instead Configures proxy options for a websocket-based mqtt connection
        Parameters:
        proxyOptions - proxy options to use for the base http connection
      • getWebsocketProxyOptions

        public HttpProxyOptions getWebsocketProxyOptions()
        Deprecated.
        use getHttpProxyOptions instead Queries proxy options for a websocket-based mqtt connection
        Returns:
        proxy options to use for the base http connection
      • setHttpProxyOptions

        public void setHttpProxyOptions​(HttpProxyOptions proxyOptions)
        Configures proxy options for the mqtt connection
        Parameters:
        proxyOptions - proxy options to use for the connection
      • getHttpProxyOptions

        public HttpProxyOptions getHttpProxyOptions()
        Queries proxy options for an mqtt connection
        Returns:
        proxy options to use for the connection
      • setWebsocketHandshakeTransform

        public void setWebsocketHandshakeTransform​(java.util.function.Consumer<WebsocketHandshakeTransformArgs> handshakeTransform)
        Set a transform operation to use on each websocket handshake http request. The transform may modify the http request before it is sent to the server. The transform MUST call handshakeTransform.complete() or handshakeTransform.completeExceptionally() when the transform is complete, failure to do so will stall the mqtt connection indefinitely. The transform operation may be asynchronous. The default websocket handshake http request uses path "/mqtt". All required headers for a websocket handshake are present, plus the optional header "Sec-WebSocket-Protocol: mqtt". This is only applicable to websocket-based mqtt connections.
        Parameters:
        handshakeTransform - http request handshake transform
      • getWebsocketHandshakeTransform

        public java.util.function.Consumer<WebsocketHandshakeTransformArgs> getWebsocketHandshakeTransform()
        Queries the handshake http request transform to use when upgrading the connection
        Returns:
        http request handshake transform
      • clone

        public MqttConnectionConfig clone()
        Creates a (shallow) clone of this config object
        Returns:
        shallow clone of this config object