Package io.vertx.mqtt
Class MqttClientOptions
- java.lang.Object
-
- io.vertx.core.net.NetworkOptions
-
- io.vertx.core.net.TCPSSLOptions
-
- io.vertx.core.net.ClientOptionsBase
-
- io.vertx.core.net.NetClientOptions
-
- io.vertx.mqtt.MqttClientOptions
-
public class MqttClientOptions extends NetClientOptions
Represents options used by the MQTT client.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_ACK_TIMEOUTstatic booleanDEFAULT_AUTO_ACKstatic booleanDEFAULT_CLEAN_SESSIONstatic StringDEFAULT_HOSTstatic intDEFAULT_KEEP_ALIVE_INTERVALstatic intDEFAULT_MAX_INFLIGHT_QUEUEstatic intDEFAULT_MAX_MESSAGE_SIZEstatic intDEFAULT_PORTstatic intDEFAULT_TSL_PORTstatic booleanDEFAULT_WILL_FLAGstatic intDEFAULT_WILL_QOSstatic booleanDEFAULT_WILL_RETAIN-
Fields inherited from class io.vertx.core.net.NetClientOptions
DEFAULT_HOSTNAME_VERIFICATION_ALGORITHM, DEFAULT_RECONNECT_ATTEMPTS, DEFAULT_RECONNECT_INTERVAL, DEFAULT_REGISTER_WRITE_HANDLER
-
Fields inherited from class io.vertx.core.net.ClientOptionsBase
DEFAULT_CONNECT_TIMEOUT, DEFAULT_METRICS_NAME
-
Fields inherited from class io.vertx.core.net.TCPSSLOptions
DEFAULT_IDLE_TIMEOUT, DEFAULT_IDLE_TIMEOUT_TIME_UNIT, DEFAULT_READ_IDLE_TIMEOUT, DEFAULT_SO_LINGER, DEFAULT_SSL, DEFAULT_SSL_ENGINE, DEFAULT_TCP_CORK, DEFAULT_TCP_FAST_OPEN, DEFAULT_TCP_KEEP_ALIVE, DEFAULT_TCP_NO_DELAY, DEFAULT_TCP_QUICKACK, DEFAULT_TCP_USER_TIMEOUT, DEFAULT_WRITE_IDLE_TIMEOUT
-
Fields inherited from class io.vertx.core.net.NetworkOptions
DEFAULT_LOG_ACTIVITY_FORMAT, DEFAULT_LOG_ENABLED, DEFAULT_RECEIVE_BUFFER_SIZE, DEFAULT_REUSE_ADDRESS, DEFAULT_REUSE_PORT, DEFAULT_SEND_BUFFER_SIZE, DEFAULT_TRAFFIC_CLASS
-
-
Constructor Summary
Constructors Constructor Description MqttClientOptions()Default constructorMqttClientOptions(JsonObject json)Create an instance of MqttClientOptions from JSONMqttClientOptions(MqttClientOptions other)Copy constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MqttClientOptionsaddCrlPath(String crlPath)Add a CRL pathMqttClientOptionsaddCrlValue(Buffer crlValue)Add a CRL valueMqttClientOptionsaddEnabledCipherSuite(String suite)Add an enabled cipher suite, appended to the ordered suites.MqttClientOptionsaddEnabledSecureTransportProtocol(String protocol)Add an enabled SSL/TLS protocols, appended to the ordered protocols.intgetAckTimeout()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.StringgetClientId()intgetKeepAliveInterval()intgetMaxInflightQueue()intgetMaxMessageSize()StringgetPassword()StringgetUsername()BuffergetWillMessageBytes()intgetWillQoS()StringgetWillTopic()booleanhasPassword()booleanhasUsername()booleanisAutoAck()booleanisAutoGeneratedClientId()booleanisAutoKeepAlive()booleanisCleanSession()booleanisWillFlag()booleanisWillRetain()MqttClientOptionssetAckTimeout(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.voidsetAutoAck(boolean autoAck)Set to false to let the application code to ack the message viaMqttPublishMessage#ack().MqttClientOptionssetAutoGeneratedClientId(boolean isAutoGeneratedClientId)Set if the MQTT client must generate clientId automatically (default is true)MqttClientOptionssetAutoKeepAlive(boolean isAutoKeepAlive)Set if the MQTT client must handle PINGREQ automatically (default is true)MqttClientOptionssetCleanSession(boolean cleanSession)Set to start with a clean session (or not)MqttClientOptionssetClientId(String clientId)Set the client identifierMqttClientOptionssetHostnameVerificationAlgorithm(String hostnameVerificationAlgorithm)Set the hostname verification algorithm interval To disable hostname verification, set hostnameVerificationAlgorithm to an empty StringMqttClientOptionssetKeepAliveInterval(int keepAliveInterval)Set the keep alive interval in secondsMqttClientOptionssetKeyCertOptions(KeyCertOptions options)Set the key/cert options.MqttClientOptionssetMaxInflightQueue(int maxInflightQueue)Set max count of unacknowledged messagesMqttClientOptionssetMaxMessageSize(int maxMessageSize)Set max MQTT message sizeMqttClientOptionssetPassword(String password)Set the passwordMqttClientOptionssetReceiveBufferSize(int receiveBufferSize)Set the TCP receive buffer sizeMqttClientOptionssetSsl(boolean ssl)Set whether SSL/TLS is enabledMqttClientOptionssetTrustAll(boolean trustAll)Set whether all server certificates should be trustedMqttClientOptionssetTrustOptions(TrustOptions options)Set the trust options.MqttClientOptionssetUsername(String username)Set the usernameMqttClientOptionssetWillFlag(boolean willFlag)Set if will information are provided on connectionMqttClientOptionssetWillMessageBytes(Buffer willMessage)Set the content of the will messageMqttClientOptionssetWillQoS(int willQoS)Set the QoS level for the will messageMqttClientOptionssetWillRetain(boolean willRetain)Set if the will message must be retainedMqttClientOptionssetWillTopic(String willTopic)Set the topic on which the will message will be publishedJsonObjecttoJson()Convert to JSONStringtoString()-
Methods inherited from class io.vertx.core.net.NetClientOptions
addNonProxyHost, getApplicationLayerProtocols, getHostnameVerificationAlgorithm, getReconnectAttempts, getReconnectInterval, isRegisterWriteHandler, removeEnabledCipherSuite, removeEnabledSecureTransportProtocol, setActivityLogDataFormat, setApplicationLayerProtocols, setConnectTimeout, setEnabledSecureTransportProtocols, setIdleTimeout, setIdleTimeoutUnit, setLocalAddress, setLogActivity, setMetricsName, setNonProxyHosts, setProxyOptions, setReadIdleTimeout, setReconnectAttempts, setReconnectInterval, setRegisterWriteHandler, setReuseAddress, setReusePort, setSendBufferSize, setSoLinger, setSslEngineOptions, setSslHandshakeTimeout, setSslHandshakeTimeoutUnit, setTcpCork, setTcpFastOpen, setTcpKeepAlive, setTcpNoDelay, setTcpQuickAck, setTrafficClass, setUseAlpn, setWriteIdleTimeout
-
Methods inherited from class io.vertx.core.net.ClientOptionsBase
getConnectTimeout, getLocalAddress, getMetricsName, getNonProxyHosts, getOrCreateSSLOptions, getProxyOptions, getSslOptions, isTrustAll, setTcpUserTimeout
-
Methods inherited from class io.vertx.core.net.TCPSSLOptions
getCrlPaths, getCrlValues, getEnabledCipherSuites, getEnabledSecureTransportProtocols, getIdleTimeout, getIdleTimeoutUnit, getKeyCertOptions, getReadIdleTimeout, getSoLinger, getSslEngineOptions, getSslHandshakeTimeout, getSslHandshakeTimeoutUnit, getTcpUserTimeout, getTrustOptions, getWriteIdleTimeout, isSsl, isTcpCork, isTcpFastOpen, isTcpKeepAlive, isTcpNoDelay, isTcpQuickAck, isUseAlpn
-
Methods inherited from class io.vertx.core.net.NetworkOptions
getActivityLogDataFormat, getLogActivity, getReceiveBufferSize, getSendBufferSize, getTrafficClass, isReuseAddress, isReusePort
-
-
-
-
Field Detail
-
DEFAULT_PORT
public static final int DEFAULT_PORT
- See Also:
- Constant Field Values
-
DEFAULT_TSL_PORT
public static final int DEFAULT_TSL_PORT
- See Also:
- Constant Field Values
-
DEFAULT_HOST
public static final String DEFAULT_HOST
- See Also:
- Constant Field Values
-
DEFAULT_WILL_QOS
public static final int DEFAULT_WILL_QOS
- See Also:
- Constant Field Values
-
DEFAULT_KEEP_ALIVE_INTERVAL
public static final int DEFAULT_KEEP_ALIVE_INTERVAL
- See Also:
- Constant Field Values
-
DEFAULT_MAX_INFLIGHT_QUEUE
public static final int DEFAULT_MAX_INFLIGHT_QUEUE
- See Also:
- Constant Field Values
-
DEFAULT_CLEAN_SESSION
public static final boolean DEFAULT_CLEAN_SESSION
- See Also:
- Constant Field Values
-
DEFAULT_WILL_FLAG
public static final boolean DEFAULT_WILL_FLAG
- See Also:
- Constant Field Values
-
DEFAULT_WILL_RETAIN
public static final boolean DEFAULT_WILL_RETAIN
- See Also:
- Constant Field Values
-
DEFAULT_MAX_MESSAGE_SIZE
public static final int DEFAULT_MAX_MESSAGE_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_ACK_TIMEOUT
public static final int DEFAULT_ACK_TIMEOUT
- See Also:
- Constant Field Values
-
DEFAULT_AUTO_ACK
public static final boolean DEFAULT_AUTO_ACK
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 Detail
-
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 void setAutoAck(boolean autoAck)
Set to false to let the application code to ack the message viaMqttPublishMessage#ack(). If true, the ack (PUBACK/PUBCOMP) will be sent by vertx-mqtt beforeMqttClient#publishHandler()execution. (default is true)- Parameters:
autoAck-
-
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:NetworkOptionsSet the TCP receive buffer size- Overrides:
setReceiveBufferSizein classNetClientOptions- 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:TCPSSLOptionsSet whether SSL/TLS is enabled- Overrides:
setSslin classNetClientOptions- 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:NetClientOptionsSet the hostname verification algorithm interval To disable hostname verification, set hostnameVerificationAlgorithm to an empty String- Overrides:
setHostnameVerificationAlgorithmin classNetClientOptions- 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:ClientOptionsBaseSet whether all server certificates should be trusted- Overrides:
setTrustAllin classNetClientOptions- 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:TCPSSLOptionsSet the key/cert options.- Overrides:
setKeyCertOptionsin classNetClientOptions- 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:TCPSSLOptionsSet the trust options.- Overrides:
setTrustOptionsin classNetClientOptions- 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:TCPSSLOptionsAdd an enabled cipher suite, appended to the ordered suites.- Overrides:
addEnabledCipherSuitein classNetClientOptions- Parameters:
suite- the suite- Returns:
- a reference to this, so the API can be used fluently
- See Also:
TCPSSLOptions.getEnabledCipherSuites()
-
addEnabledSecureTransportProtocol
public MqttClientOptions addEnabledSecureTransportProtocol(String protocol)
Description copied from class:TCPSSLOptionsAdd an enabled SSL/TLS protocols, appended to the ordered protocols.- Overrides:
addEnabledSecureTransportProtocolin classNetClientOptions- 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:TCPSSLOptionsAdd a CRL path- Overrides:
addCrlPathin classNetClientOptions- 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:TCPSSLOptionsAdd a CRL value- Overrides:
addCrlValuein classNetClientOptions- 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:ClientOptionsBaseConvert to JSON- Overrides:
toJsonin classNetClientOptions- Returns:
- the JSON
-
-