Package software.amazon.awssdk.crt.mqtt
Class MqttConnectionConfig
- java.lang.Object
-
- software.amazon.awssdk.crt.CrtResource
-
- software.amazon.awssdk.crt.mqtt.MqttConnectionConfig
-
- All Implemented Interfaces:
AutoCloseable
public final class MqttConnectionConfig extends CrtResource
Encapsulates all per-mqtt-connection configuration
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class software.amazon.awssdk.crt.CrtResource
CrtResource.ResourceInstance
-
-
Constructor Summary
Constructors Constructor Description MqttConnectionConfig()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description MqttConnectionConfig
clone()
Creates a (shallow) clone of this config objectboolean
getCleanSession()
Queries whether or not the service should try to resume prior subscriptions, if it has anyString
getClientId()
Queries the client_id being used by a connectionMqttClientConnectionEvents
getConnectionCallbacks()
Queries the connection-related callbacks for a connectionString
getEndpoint()
Queries the IoT endpoint used by a connectionHttpProxyOptions
getHttpProxyOptions()
Queries proxy options for an mqtt connectionint
getKeepAliveMs()
Deprecated.Queries the MQTT keep-alive via PING messages.int
getKeepAliveSecs()
Queries the MQTT keep-alive via PING messages.long
getMaxReconnectTimeoutSecs()
Return the maximum reconnect timeout.long
getMinReconnectTimeoutSecs()
Return the minimum reconnect timeout.Mqtt5Client
getMqtt5Client()
Queries the mqtt5 client to use for a connectionMqttClient
getMqttClient()
Queries the mqtt client to use for a connectionString
getPassword()
Queries the password to use as part of the CONNECT attemptint
getPingTimeoutMs()
Queries ping timeout value.int
getPort()
Queries the port to connect to.int
getProtocolOperationTimeoutMs()
Queries timeout value for requests that response is required on healthy connection.SocketOptions
getSocketOptions()
Queries the common settings to use for a connection's socketString
getUsername()
Queries the username to use as part of the CONNECT attemptboolean
getUseWebsockets()
Queries whether or not to use websockets for the mqtt connectionConsumer<WebsocketHandshakeTransformArgs>
getWebsocketHandshakeTransform()
Queries the handshake http request transform to use when upgrading the connectionHttpProxyOptions
getWebsocketProxyOptions()
Deprecated.use getHttpProxyOptions instead Queries proxy options for a websocket-based mqtt connectionMqttMessage
getWillMessage()
Queries the last will and testament message to be delivered to a topic when a connection disconnectsQualityOfService
getWillQos()
Deprecated.Query QoS directly from the will'sMqttMessage
.boolean
getWillRetain()
Deprecated.Query retain directly from the will'sMqttMessage
.void
setCleanSession(boolean cleanSession)
Configures whether or not the service should try to resume prior subscriptions, if it has anyvoid
setClientId(String clientId)
Configures the client_id to use with a connectionvoid
setConnectionCallbacks(MqttClientConnectionEvents connectionCallbacks)
Configures the connection-related callbacks for a connectionvoid
setEndpoint(String endpoint)
Configures the IoT endpoint for a connectionvoid
setHttpProxyOptions(HttpProxyOptions proxyOptions)
Configures proxy options for the mqtt connectionvoid
setKeepAliveMs(int keepAliveMs)
Deprecated.Configures MQTT keep-alive via PING messages.void
setKeepAliveSecs(int keepAliveSecs)
Configures MQTT keep-alive via PING messages.void
setLogin(String user, String pass)
Sets the login credentials for a connection.void
setMqtt5Client(Mqtt5Client mqtt5Client)
Configures the mqtt5 client to use for a connectionvoid
setMqttClient(MqttClient mqttClient)
Configures the mqtt client to use for a connectionvoid
setPassword(String password)
Configures the password to use as part of the CONNECT attemptvoid
setPingTimeoutMs(int pingTimeoutMs)
Configures ping timeout value.void
setPort(int port)
Configures the port to connect to.void
setProtocolOperationTimeoutMs(int protocolOperationTimeoutMs)
Configures timeout value for requests that response is required on healthy connection.void
setReconnectTimeoutSecs(long minTimeoutSecs, long maxTimeoutSecs)
Configures the minimum and maximum reconnect timeouts.void
setSocketOptions(SocketOptions socketOptions)
Configures the common settings to use for a connection's socketvoid
setUsername(String username)
Configures the username to use as part of the CONNECT attemptvoid
setUseWebsockets(boolean useWebsockets)
Configures whether or not to use websockets for the mqtt connectionvoid
setWebsocketHandshakeTransform(Consumer<WebsocketHandshakeTransformArgs> handshakeTransform)
Set a transform operation to use on each websocket handshake http request.void
setWebsocketProxyOptions(HttpProxyOptions proxyOptions)
Deprecated.use setHttpProxyOptions instead Configures proxy options for a websocket-based mqtt connectionvoid
setWillMessage(MqttMessage willMessage)
Configures the last will and testament message to be delivered to a topic when a connection disconnectsvoid
setWillQos(QualityOfService qos)
Deprecated.Set QoS directly on the will'sMqttMessage
.void
setWillRetain(boolean retain)
Deprecated.Set retain directly on the will'sMqttMessage
.-
Methods inherited from class software.amazon.awssdk.crt.CrtResource
addRef, addReferenceTo, close, collectNativeResource, collectNativeResources, decRef, getNativeHandle, getResourceLogDescription, isNull, logNativeResources, logNativeResources, removeReferenceTo, setDescription, waitForNoResources
-
-
-
-
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(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 String getClientId()
Queries the client_id being used by a connection- Returns:
- The client id for a connection.
-
setEndpoint
public void setEndpoint(String endpoint)
Configures the IoT endpoint for a connection- Parameters:
endpoint
- The IoT endpoint to connect to
-
getEndpoint
public 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 withmaxTimeoutSecs
- 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(String user, String pass) throws MqttException
Sets the login credentials for a connection.- Parameters:
user
- Login usernamepass
- Login password- Throws:
MqttException
-
setUsername
public void setUsername(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 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(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 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'sMqttMessage
.- Parameters:
qos
- Quality of Service
-
getWillQos
@Deprecated public QualityOfService getWillQos()
Deprecated.Query QoS directly from the will'sMqttMessage
.- Returns:
- Quality of Service
-
setWillRetain
@Deprecated public void setWillRetain(boolean retain)
Deprecated.Set retain directly on the will'sMqttMessage
.- Parameters:
retain
- whether will's should be sent with retain property set
-
getWillRetain
@Deprecated public boolean getWillRetain()
Deprecated.Query retain directly from the will'sMqttMessage
.- 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(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 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
-
-