Class MqttClientOptions


public class MqttClientOptions extends NetClientOptions
Represents options used by the MQTT client.
  • Field Details

  • Constructor Details

    • MqttClientOptions

      public MqttClientOptions()
      Default constructor
    • MqttClientOptions

      public MqttClientOptions(JsonObject json)
      Create an instance of MqttClientOptions from JSON
      Parameters:
      json - the JSON
    • MqttClientOptions

      public MqttClientOptions(MqttClientOptions other)
      Copy constructor
      Parameters:
      other - the options to copy
  • Method Details

    • hasUsername

      public boolean hasUsername()
      Returns:
      if username is provided
    • hasPassword

      public boolean hasPassword()
      Returns:
      if password is provided
    • isCleanSession

      public boolean isCleanSession()
      Returns:
      if client wants to start with a clean session
    • isWillFlag

      public boolean isWillFlag()
      Returns:
      if will information are provided on connection
    • isWillRetain

      public boolean isWillRetain()
      Returns:
      if the will messages must be retained
    • getWillQoS

      public int getWillQoS()
      Returns:
      the QoS level for the will message
    • getKeepAliveInterval

      public int getKeepAliveInterval()
      Returns:
      the keep alive interval (in seconds)
    • getUsername

      public String getUsername()
      Returns:
      provided username
    • getPassword

      public String getPassword()
      Returns:
      provided password
    • getClientId

      public String getClientId()
      Returns:
      client identifier
    • getWillTopic

      public String getWillTopic()
      Returns:
      topic on which the will message will be published
    • getWillMessageBytes

      public Buffer getWillMessageBytes()
      Returns:
      will message bytes content
    • setClientId

      public MqttClientOptions setClientId(String clientId)
      Set the client identifier
      Parameters:
      clientId - client identifier
      Returns:
      current options instance
    • setUsername

      public MqttClientOptions setUsername(String username)
      Set the username
      Parameters:
      username - username
      Returns:
      current options instance
    • setPassword

      public MqttClientOptions setPassword(String password)
      Set the password
      Parameters:
      password - password
      Returns:
      current options instance
    • setWillTopic

      public MqttClientOptions setWillTopic(String willTopic)
      Set the topic on which the will message will be published
      Parameters:
      willTopic - topic on which the will message will be published
      Returns:
      current options instance
    • setWillMessageBytes

      public MqttClientOptions setWillMessageBytes(Buffer willMessage)
      Set the content of the will message
      Parameters:
      willMessage - content of the will message
      Returns:
      current options instance
    • setCleanSession

      public MqttClientOptions setCleanSession(boolean cleanSession)
      Set to start with a clean session (or not)
      Parameters:
      cleanSession - if clean session should be activated
      Returns:
      current options instance
    • setWillFlag

      public MqttClientOptions setWillFlag(boolean willFlag)
      Set if will information are provided on connection
      Parameters:
      willFlag - if will information are provided on connection
      Returns:
      current options instance
    • setWillQoS

      public MqttClientOptions setWillQoS(int willQoS)
      Set the QoS level for the will message
      Parameters:
      willQoS - QoS level for the will message
      Returns:
      current options instance
    • setWillRetain

      public MqttClientOptions setWillRetain(boolean willRetain)
      Set if the will message must be retained
      Parameters:
      willRetain - if thw will message must be retained
      Returns:
      current options instance
    • setKeepAliveInterval

      public MqttClientOptions setKeepAliveInterval(int keepAliveInterval)
      Set the keep alive interval in seconds
      Parameters:
      keepAliveInterval - keep alive interval in seconds
      Returns:
      current options instance
    • getAckTimeout

      public int getAckTimeout()
      Gets the time in seconds after which the client stops waiting for a PUBACK, PUBREC or PUBCOMP packet from the server in response to a packet it has sent.

      The default value of this property is 10s.

      Returns:
      timeout in seconds
    • setAckTimeout

      public MqttClientOptions setAckTimeout(int ackTimeoutSeconds)
      Sets the time in seconds after which the client will stop waiting for a PUBACK, PUBREC or PUBCOMP packet from the server in response to a packet it has sent.

      The default value of this property is -1 which indicates that the client should wait an unlimited time for the server's acknowledgement.

      Parameters:
      ackTimeoutSeconds - timeout in seconds
      Returns:
      current options instance
      Throws:
      IllegalArgumentException - if the timeout is 0 or < -1.
    • getMaxInflightQueue

      public int getMaxInflightQueue()
      Returns:
      max count of unacknowledged messages
    • setMaxInflightQueue

      public MqttClientOptions setMaxInflightQueue(int maxInflightQueue)
      Set max count of unacknowledged messages
      Parameters:
      maxInflightQueue - max count of unacknowledged messages
      Returns:
      current options instance
    • setAutoKeepAlive

      public MqttClientOptions setAutoKeepAlive(boolean isAutoKeepAlive)
      Set if the MQTT client must handle PINGREQ automatically (default is true)
      Parameters:
      isAutoKeepAlive - ping request handled automatically
      Returns:
      current options instance
    • setAutoGeneratedClientId

      public MqttClientOptions setAutoGeneratedClientId(boolean isAutoGeneratedClientId)
      Set if the MQTT client must generate clientId automatically (default is true)
      Parameters:
      isAutoGeneratedClientId - clientId generated automatically
      Returns:
      current options instance
    • isAutoAck

      public boolean isAutoAck()
      Returns:
      if the ack (PUBACK/PUBCOMP) will be sent automatically by vertx-mqtt
    • setAutoAck

      public MqttClientOptions setAutoAck(boolean autoAck)
      Set to false to let the application code to ack the message via
      invalid reference
      MqttPublishMessage#ack()
      . If true, the ack (PUBACK/PUBCOMP) will be sent by vertx-mqtt before
      invalid reference
      MqttClient#publishHandler()
      execution. (default is true)
      Parameters:
      autoAck -
    • getRecvByteBufAllocatorSize

      public int getRecvByteBufAllocatorSize()
      Returns:
      the size for the FixedRecvByteBufAllocator, or -1 if not set
    • setRecvByteBufAllocatorSize

      public MqttClientOptions setRecvByteBufAllocatorSize(int recvByteBufAllocatorSize)
      Set the size for the FixedRecvByteBufAllocator used on the channel. Use -1 (default) to leave the allocator unchanged.
      Parameters:
      recvByteBufAllocatorSize - the fixed buffer size in bytes, or -1 to disable
      Returns:
      current options instance
    • isAutoKeepAlive

      public boolean isAutoKeepAlive()
      Returns:
      if the PINGREQ is handled automatically
    • isAutoGeneratedClientId

      public boolean isAutoGeneratedClientId()
      Returns:
      if clientId generated automatically
    • getMaxMessageSize

      public int getMaxMessageSize()
      Returns:
      max MQTT message size
    • setReceiveBufferSize

      public MqttClientOptions setReceiveBufferSize(int receiveBufferSize)
      Description copied from class: NetworkOptions
      Set the TCP receive buffer size
      Overrides:
      setReceiveBufferSize in class NetClientOptions
      Parameters:
      receiveBufferSize - the buffers size, in bytes
      Returns:
      a reference to this, so the API can be used fluently
    • setMaxMessageSize

      public MqttClientOptions setMaxMessageSize(int maxMessageSize)
      Set max MQTT message size
      Parameters:
      maxMessageSize - max MQTT message size
      Returns:
      MQTT client options instance
    • setSsl

      public MqttClientOptions setSsl(boolean ssl)
      Description copied from class: TCPSSLOptions
      Set whether SSL/TLS is enabled
      Overrides:
      setSsl in class NetClientOptions
      Parameters:
      ssl - true if enabled
      Returns:
      a reference to this, so the API can be used fluently
    • setHostnameVerificationAlgorithm

      public MqttClientOptions setHostnameVerificationAlgorithm(String hostnameVerificationAlgorithm)
      Description copied from class: NetClientOptions
      Set the hostname verification algorithm interval To disable hostname verification, set hostnameVerificationAlgorithm to an empty String
      Overrides:
      setHostnameVerificationAlgorithm in class NetClientOptions
      Parameters:
      hostnameVerificationAlgorithm - should be HTTPS, LDAPS or an empty String
      Returns:
      a reference to this, so the API can be used fluently
    • setTrustAll

      public MqttClientOptions setTrustAll(boolean trustAll)
      Description copied from class: ClientOptionsBase
      Set whether all server certificates should be trusted
      Overrides:
      setTrustAll in class NetClientOptions
      Parameters:
      trustAll - true if all should be trusted
      Returns:
      a reference to this, so the API can be used fluently
    • setKeyCertOptions

      public MqttClientOptions setKeyCertOptions(KeyCertOptions options)
      Description copied from class: TCPSSLOptions
      Set the key/cert options.
      Overrides:
      setKeyCertOptions in class NetClientOptions
      Parameters:
      options - the key store options
      Returns:
      a reference to this, so the API can be used fluently
    • setTrustOptions

      public MqttClientOptions setTrustOptions(TrustOptions options)
      Description copied from class: TCPSSLOptions
      Set the trust options.
      Overrides:
      setTrustOptions in class NetClientOptions
      Parameters:
      options - the trust options
      Returns:
      a reference to this, so the API can be used fluently
    • addEnabledCipherSuite

      public MqttClientOptions addEnabledCipherSuite(String suite)
      Description copied from class: TCPSSLOptions
      Add an enabled cipher suite, appended to the ordered suites.
      Overrides:
      addEnabledCipherSuite in class NetClientOptions
      Parameters:
      suite - the suite
      Returns:
      a reference to this, so the API can be used fluently
      See Also:
    • addEnabledSecureTransportProtocol

      public MqttClientOptions addEnabledSecureTransportProtocol(String protocol)
      Description copied from class: TCPSSLOptions
      Add an enabled SSL/TLS protocols, appended to the ordered protocols.
      Overrides:
      addEnabledSecureTransportProtocol in class NetClientOptions
      Parameters:
      protocol - the SSL/TLS protocol to enable
      Returns:
      a reference to this, so the API can be used fluently
    • addCrlPath

      public MqttClientOptions addCrlPath(String crlPath) throws NullPointerException
      Description copied from class: TCPSSLOptions
      Add a CRL path
      Overrides:
      addCrlPath in class NetClientOptions
      Parameters:
      crlPath - the path
      Returns:
      a reference to this, so the API can be used fluently
      Throws:
      NullPointerException
    • addCrlValue

      public MqttClientOptions addCrlValue(Buffer crlValue) throws NullPointerException
      Description copied from class: TCPSSLOptions
      Add a CRL value
      Overrides:
      addCrlValue in class NetClientOptions
      Parameters:
      crlValue - the value
      Returns:
      a reference to this, so the API can be used fluently
      Throws:
      NullPointerException
    • toJson

      public JsonObject toJson()
      Description copied from class: ClientOptionsBase
      Convert to JSON
      Overrides:
      toJson in class NetClientOptions
      Returns:
      the JSON
    • toString

      public String toString()
      Overrides:
      toString in class Object