Package 

Class MqttConnectOptions


  • 
    public class MqttConnectOptions
    
                        

    Holds the set of options that control how the client connects to a server.

    • Constructor Detail

      • MqttConnectOptions

        MqttConnectOptions()
        Constructs a new MqttConnectOptions object using the default values.
    • Method Detail

      • setKeepAliveInterval

         void setKeepAliveInterval(int keepAliveInterval)

        Sets the "keep alive" interval. This value, measured in seconds, defines the maximum time interval between messages sent or received. It enables the client to detect if the server is no longer available, without having to wait for the TCP/IP timeout. The client will ensure that at least one message travels across the network within each keep alive period. In the absence of a data-related message during the time period, the client sends a very small "ping" message, which the server will acknowledge. A value of 0 disables keepalive processing in the client.

        The default value is 60 seconds

        Parameters:
        keepAliveInterval - the interval, measured in seconds, must be >= 0.
      • getWillMessage

         MqttMessage getWillMessage()

        Returns the message to be sent as last will and testament (LWT). The returned object is "read only". Calling any "setter" methods on the returned object will result in an IllegalStateException being thrown.

      • setUserName

         void setUserName(String userName)

        Sets the user name to use for the connection.

      • getPassword

         Array<char> getPassword()

        Returns the password to use for the connection.

      • setPassword

         void setPassword(Array<char> password)

        Sets the password to use for the connection.

      • getSocketFactory

         SocketFactory getSocketFactory()

        Returns the socket factory that will be used when connecting, or null if one has not been set.

      • setSocketFactory

         void setSocketFactory(SocketFactory socketFactory)

        Sets the SocketFactory to use. This allows an application to apply its own policies around the creation of network sockets. If using an SSL connection, an SSLSocketFactory can be used to supply application-specific security settings.

        Parameters:
        socketFactory - the factory to use.
      • setCleanSession

         void setCleanSession(boolean cleanSession)

        Sets whether the client and server should remember state across restarts and reconnects.

        • If set to false both the client and server will maintain state across restarts of the client, the server and the connection. As state is maintained:
          • Message delivery will be reliable meeting the specified QOS even if the client, server or connection are restarted.
          • The server will treat a subscription as durable.
        • If set to true the client and server will not maintain state across restarts of the client, the server or the connection. This means
          • Message delivery to the specified QOS cannot be maintained if the client, server or connection are restarted
          • The server will treat a subscription as non-durable
      • setConnectionTimeout

         void setConnectionTimeout(int connectionTimeout)

        Sets the connection timeout value. This value, measured in seconds, defines the maximum time interval the client will wait for the network connection to the MQTT server to be established. The default timeout is 30 seconds. A value of 0 disables timeout processing meaning the client will wait until the network connection is made successfully or fails.

        Parameters:
        connectionTimeout - the timeout value, measured in seconds.
      • setHandshakeTimeout

         void setHandshakeTimeout(int handshakeTimeout)

        Sets the handshake timeout value.

        Parameters:
        handshakeTimeout - the timeout value, measured in seconds.
      • setReadTimeout

         void setReadTimeout(int readTimeout)

        Sets the read timeout value. This value, measured in seconds, defines the maximum time interval a read() call on the InputStream associated with this Socket will block for. The default timeout is 360 seconds. A value of 0 is interpreted as an infinite timeout.

        Parameters:
        readTimeout - the timeout value, measured in seconds.
      • setServerURIs

         void setServerURIs(Array<String> array)

        Set a list of one or more serverURIs the client may connect to.

        Each serverURI specifies the address of a server that the client may connect to. Two types of connection are supported tcp:// for a TCP connection and ssl:// for a TCP connection secured by SSL/TLS. For example:

        • tcp://localhost:1883
        • ssl://localhost:8883
        If the port is not specified, it will default to 1883 for tcp://" URIs, and 8883 for ssl:// URIs.

        If serverURIs is set then it overrides the serverURI parameter passed in on the constructor of the MQTT client.

        When an attempt to connect is initiated the client will start with the first serverURI in the list and work through the list until a connection is established with a server. If a connection cannot be made to any of the servers then the connect attempt fails.

        Specifying a list of servers that a client may connect to has several uses:

        • High Availability and reliable message delivery

          Some MQTT servers support a high availability feature where two or more "equal" MQTT servers share state. An MQTT client can connect to any of the "equal" servers and be assured that messages are reliably delivered and durable subscriptions are maintained no matter which server the client connects to.

          The cleansession flag must be set to false if durable subscriptions and/or reliable message delivery is required.

        • Hunt List

          A set of servers may be specified that are not "equal" (as in the high availability option). As no state is shared across the servers reliable message delivery and durable subscriptions are not valid. The cleansession flag must be set to true if the hunt list mode is used

        Parameters:
        array - of serverURIs
      • setWill

         void setWill(MqttTopic topic, Array<byte> payload, int qos, boolean retained)

        Sets the "Last Will and Testament" (LWT) for the connection. In the event that this client unexpectedly loses its connection to the server, the server will publish a message to itself using the supplied details.

        Parameters:
        topic - the topic to publish to.
        payload - the byte payload for the message.
        qos - the quality of service to publish the message at (0, 1 or 2).
        retained - whether or not the message should be retained.
      • setWill

         void setWill(String topic, Array<byte> payload, int qos, boolean retained)

        Sets the "Last Will and Testament" (LWT) for the connection. In the event that this client unexpectedly loses its connection to the server, the server will publish a message to itself using the supplied details.

        Parameters:
        topic - the topic to publish to.
        payload - the byte payload for the message.
        qos - the quality of service to publish the message at (0, 1 or 2).
        retained - whether or not the message should be retained.
      • setSSLProperties

         void setSSLProperties(Properties props)

        Sets the SSL properties for the connection. Note that these properties are only valid if an implementation of the Java Secure Socket Extensions (JSSE) is available. These properties are not used if a SocketFactory has been set using setSocketFactory. The following properties can be used:

      • isCleanSession

         boolean isCleanSession()

        Returns whether the client and server should remember state for the client across reconnects.