Package software.amazon.awssdk.iot
Class AwsIotMqtt5ClientBuilder
- java.lang.Object
-
- software.amazon.awssdk.crt.CrtResource
-
- software.amazon.awssdk.iot.AwsIotMqtt5ClientBuilder
-
- All Implemented Interfaces:
AutoCloseable
public class AwsIotMqtt5ClientBuilder extends software.amazon.awssdk.crt.CrtResourceBuilders for making MQTT5 clients with different connection methods for AWS IoT Core.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAwsIotMqtt5ClientBuilder.MqttConnectCustomAuthConfigConfiguration options specific to AWS IoT Core custom authentication features.static classAwsIotMqtt5ClientBuilder.WebsocketSigv4ConfigWebsocket-specific MQTT5 connection AWS IoT configuration options
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description software.amazon.awssdk.crt.mqtt5.Mqtt5Clientbuild()Constructs an MQTT5 client object configured with the options set.static StringextractRegionFromEndpoint(String endpoint)Attempts to determine the AWS region associated with an endpoint.static AwsIotMqtt5ClientBuildernewDirectMqttBuilderWithCustomAuth(String hostName, AwsIotMqtt5ClientBuilder.MqttConnectCustomAuthConfig customAuthConfig)Creates a new MQTT5 client builder that will use direct MQTT and a custom authenticator controlled by the username and password values.static AwsIotMqtt5ClientBuildernewDirectMqttBuilderWithJavaKeystore(String hostName, KeyStore keyStore, String certificateAlias, String certificatePassword)Creates a new MQTT5 client builder using a certificate and key stored in the passed-in Java keystore.static AwsIotMqtt5ClientBuildernewDirectMqttBuilderWithMtlsFromMemory(String hostName, String certificate, String privateKey)Creates a new MQTT5 client builder with mTLS cert pair in memorystatic AwsIotMqtt5ClientBuildernewDirectMqttBuilderWithMtlsFromPath(String hostName, String certificatePath, String privateKeyPath)Creates a new MQTT5 client builder with mTLS file paths.static AwsIotMqtt5ClientBuildernewDirectMqttBuilderWithMtlsFromPkcs11(String hostName, String pkcs12Path, String pkcs12Password)Deprecated.Use alternate newDirectMqttBuilderWithMtlsFromPkcs12().static AwsIotMqtt5ClientBuildernewDirectMqttBuilderWithMtlsFromPkcs11(String hostName, software.amazon.awssdk.crt.io.TlsContextPkcs11Options pkcs11Options)Creates a new MQTT5 client builder with mTLS using a PKCS#11 library for private key operations NOTE: This configuration only works on Unix devices.static AwsIotMqtt5ClientBuildernewDirectMqttBuilderWithMtlsFromPkcs12(String hostName, String pkcs12Path, String pkcs12Password)Create a new builder with mTLS, using a PKCS12 library for private key operations.static AwsIotMqtt5ClientBuildernewDirectMqttBuilderWithMtlsFromWindowsCertStorePath(String hostName, String certificatePath)Creates a new MQTT5 client builder with mTLS using a certificate in a Windows certificate store.static AwsIotMqtt5ClientBuildernewDirectMtlsCustomKeyOperationsBuilder(String hostName, software.amazon.awssdk.crt.io.TlsContextCustomKeyOperationOptions operationOptions)Creates a new MQTT5 client builder with mTLS using a custom handler for private key operations NOTE: This configuration only works on Unix devices.static AwsIotMqtt5ClientBuildernewMqttBuilder(String hostName)Creates a new MQTT5 client builder with default TLS options.static AwsIotMqtt5ClientBuildernewMqttBuilderFromMqtt311ConnectionConfig(software.amazon.awssdk.crt.mqtt.MqttConnectionConfig mqtt311Config, software.amazon.awssdk.crt.io.TlsContextOptions tlsOptions)Creates a new MQTT5 client builder using a MqttConnectionConfig.static AwsIotMqtt5ClientBuildernewWebsocketMqttBuilderWithCustomAuth(String hostName, AwsIotMqtt5ClientBuilder.MqttConnectCustomAuthConfig customAuthConfig)Creates a new MQTT5 client builder that will use websocket connection and a custom authenticator controlled by the username and password values.static AwsIotMqtt5ClientBuildernewWebsocketMqttBuilderWithSigv4Auth(String hostName, AwsIotMqtt5ClientBuilder.WebsocketSigv4Config config)Create a new MQTT5 client builder that will use websockets and AWS Sigv4 signing to establish mutually-authenticated (mTLS) connections.AwsIotMqtt5ClientBuilderwithAckTimeoutSeconds(Long ackTimeoutSeconds)Overrides the time interval to wait for an ack after sending a QoS 1+ PUBLISH, SUBSCRIBE, or UNSUBSCRIBE before failing the operation.AwsIotMqtt5ClientBuilderwithCertificateAuthority(String caRoot)Overrides the default trust store.AwsIotMqtt5ClientBuilderwithCertificateAuthorityFromPath(String caDirPath, String caFilePath)Overrides the default system trust store.AwsIotMqtt5ClientBuilderwithClientId(String clientId)Sets the unique string identifying the client to the server.AwsIotMqtt5ClientBuilderwithConnackTimeoutMs(Long connackTimeoutMs)Overrides the time interval to wait after sending a CONNECT request for a CONNACK to arrive.AwsIotMqtt5ClientBuilderwithConnectProperties(software.amazon.awssdk.crt.mqtt5.packets.ConnectPacket.ConnectPacketBuilder connectPacket)Overrides all configurable options with respect to the CONNECT packet sent by the client, including the will.AwsIotMqtt5ClientBuilderwithExtendedValidationAndFlowControlOptions(software.amazon.awssdk.crt.mqtt5.Mqtt5ClientOptions.ExtendedValidationAndFlowControlOptions extendedValidationAndFlowControlOptions)Overrides additional controls for client behavior with respect to operation validation and flow control; these checks go beyond the base MQTT5 spec to respect limits of specific MQTT brokers.AwsIotMqtt5ClientBuilderwithHttpProxyOptions(software.amazon.awssdk.crt.http.HttpProxyOptions httpProxyOptions)Overrides (tunneling) HTTP proxy usage when establishing MQTT connections.AwsIotMqtt5ClientBuilderwithKeepAliveIntervalSeconds(Long keepAliveIntervalSeconds)Sets the maximum time interval, in seconds, that is permitted to elapse between the point at which the client finishes transmitting one MQTT packet and the point it starts sending the next.AwsIotMqtt5ClientBuilderwithLifeCycleEvents(software.amazon.awssdk.crt.mqtt5.Mqtt5ClientOptions.LifecycleEvents lifecycleEvents)Sets the LifeCycleEvents that will be called by the client when receives a life cycle events.AwsIotMqtt5ClientBuilderwithMaximumPacketSizeBytes(Long maximumPacketSizeBytes)Sets the maximum packet size the client is willing to handle.AwsIotMqtt5ClientBuilderwithMaxReconnectDelayMs(Long maxReconnectDelayMs)Overrides the maximum amount of time to wait to reconnect after a disconnect.AwsIotMqtt5ClientBuilderwithMinConnectedTimeToResetReconnectDelayMs(Long minConnectedTimeToResetReconnectDelayMs)Overrides the amount of time that must elapse with an established connection before the reconnect delay is reset to the minimum.AwsIotMqtt5ClientBuilderwithMinimumTlsVersion(software.amazon.awssdk.crt.io.TlsContextOptions.TlsVersions minimumTlsVersion)Sets the minimum TLS version that is acceptable for connection establishment.AwsIotMqtt5ClientBuilderwithMinReconnectDelayMs(Long minReconnectDelayMs)Overrides the minimum amount of time to wait to reconnect after a disconnect.AwsIotMqtt5ClientBuilderwithOfflineQueueBehavior(software.amazon.awssdk.crt.mqtt5.Mqtt5ClientOptions.ClientOfflineQueueBehavior offlineQueueBehavior)Overrides how disconnects affect the queued and in-progress operations tracked by the client.AwsIotMqtt5ClientBuilderwithPingTimeoutMs(Long pingTimeoutMs)Overrides the time interval to wait after sending a PINGREQ for a PINGRESP to arrive.AwsIotMqtt5ClientBuilderwithPort(Long port)Overrides the port to connect to on the IoT endpointAwsIotMqtt5ClientBuilderwithPublishEvents(software.amazon.awssdk.crt.mqtt5.Mqtt5ClientOptions.PublishEvents publishEvents)Sets the PublishEvents that will be called by the client when it receives a publish packet.AwsIotMqtt5ClientBuilderwithReceiveMaximum(Long receiveMaximum)Sets the maximum number of in-flight QoS 1 and 2 messages the client is willing to handle.AwsIotMqtt5ClientBuilderwithRequestProblemInformation(Boolean requestProblemInformation)Sets whether requests that the server send additional diagnostic information (via response string or user properties) in DisconnectPacket or ConnAckPacket from the server.AwsIotMqtt5ClientBuilderwithRequestResponseInformation(Boolean requestResponseInformation)Sets whether requests that the server send response information in the subsequent ConnAckPacket.AwsIotMqtt5ClientBuilderwithRetryJitterMode(software.amazon.awssdk.crt.io.ExponentialBackoffRetryOptions.JitterMode jitterMode)Overrides how the reconnect delay is modified in order to smooth out the distribution of reconnect attempt time points for a large set of reconnecting clients.AwsIotMqtt5ClientBuilderwithSessionBehavior(software.amazon.awssdk.crt.mqtt5.Mqtt5ClientOptions.ClientSessionBehavior sessionBehavior)Overrides how the MQTT5 client should behave with respect to MQTT sessions.AwsIotMqtt5ClientBuilderwithSessionExpiryIntervalSeconds(Long sessionExpiryIntervalSeconds)Sets the time interval, in seconds, that the client requests the server to persist this connection's MQTT session state for.AwsIotMqtt5ClientBuilderwithSocketOptions(software.amazon.awssdk.crt.io.SocketOptions socketOptions)Overrides the socket properties of the underlying MQTT connections made by the client.AwsIotMqtt5ClientBuilderwithTlsCipherPreference(software.amazon.awssdk.crt.io.TlsCipherPreference tlsCipherPreference)Sets the TLS cipher preference.AwsIotMqtt5ClientBuilderwithTopicAliasingOptions(software.amazon.awssdk.crt.mqtt5.TopicAliasingOptions options)Overrides how the MQTT5 client should behave with respect to MQTT5 topic aliasing.AwsIotMqtt5ClientBuilderwithUserProperties(List<software.amazon.awssdk.crt.mqtt5.packets.UserProperty> userProperties)Sets the list of MQTT5 user properties included with the packet.AwsIotMqtt5ClientBuilderwithWill(software.amazon.awssdk.crt.mqtt5.packets.PublishPacket will)Sets the definition of a message to be published when the connection's session is destroyed by the server or when the will delay interval has elapsed, whichever comes first.AwsIotMqtt5ClientBuilderwithWillDelayIntervalSeconds(Long willDelayIntervalSeconds)Sets the time interval, in seconds, that the server should wait (for a session reconnection) before sending the will message associated with the connection's session.
-
-
-
Method Detail
-
newDirectMqttBuilderWithMtlsFromPath
public static AwsIotMqtt5ClientBuilder newDirectMqttBuilderWithMtlsFromPath(String hostName, String certificatePath, String privateKeyPath)
Creates a new MQTT5 client builder with mTLS file paths.- Parameters:
hostName- - AWS IoT endpoint to connect tocertificatePath- - Path to certificate, in PEM formatprivateKeyPath- - Path to private key, in PEM format- Returns:
- - A new AwsIotMqtt5ClientBuilder
-
newDirectMqttBuilderWithMtlsFromMemory
public static AwsIotMqtt5ClientBuilder newDirectMqttBuilderWithMtlsFromMemory(String hostName, String certificate, String privateKey)
Creates a new MQTT5 client builder with mTLS cert pair in memory- Parameters:
hostName- - AWS IoT endpoint to connect tocertificate- - Certificate, in PEM formatprivateKey- - Private key, in PEM format- Returns:
- - A new AwsIotMqtt5ClientBuilder
-
newDirectMqttBuilderWithMtlsFromPkcs11
public static AwsIotMqtt5ClientBuilder newDirectMqttBuilderWithMtlsFromPkcs11(String hostName, software.amazon.awssdk.crt.io.TlsContextPkcs11Options pkcs11Options)
Creates a new MQTT5 client builder with mTLS using a PKCS#11 library for private key operations NOTE: This configuration only works on Unix devices.- Parameters:
hostName- - AWS IoT endpoint to connect topkcs11Options- - PKCS#11 options- Returns:
- - A new AwsIotMqtt5ClientBuilder
-
newDirectMtlsCustomKeyOperationsBuilder
public static AwsIotMqtt5ClientBuilder newDirectMtlsCustomKeyOperationsBuilder(String hostName, software.amazon.awssdk.crt.io.TlsContextCustomKeyOperationOptions operationOptions)
Creates a new MQTT5 client builder with mTLS using a custom handler for private key operations NOTE: This configuration only works on Unix devices.- Parameters:
hostName- - AWS IoT endpoint to connect tooperationOptions- - Options for using a custom handler- Returns:
- - A new AwsIotMqtt5ClientBuilder
-
newDirectMqttBuilderWithMtlsFromWindowsCertStorePath
public static AwsIotMqtt5ClientBuilder newDirectMqttBuilderWithMtlsFromWindowsCertStorePath(String hostName, String certificatePath)
Creates a new MQTT5 client builder with mTLS using a certificate in a Windows certificate store. NOTE: This configuration only works on Windows devices.- Parameters:
hostName- - AWS IoT endpoint to connect tocertificatePath- - Path to certificate in a Windows certificate store. The path must use backslashes and end with the certificate's thumbprint. Example: `CurrentUser\MY\A11F8A9B5DF5B98BA3508FBCA575D09570E0D2C6`- Returns:
- - A new AwsIotMqtt5ClientBuilder
-
newDirectMqttBuilderWithCustomAuth
public static AwsIotMqtt5ClientBuilder newDirectMqttBuilderWithCustomAuth(String hostName, AwsIotMqtt5ClientBuilder.MqttConnectCustomAuthConfig customAuthConfig)
Creates a new MQTT5 client builder that will use direct MQTT and a custom authenticator controlled by the username and password values.- Parameters:
hostName- - AWS IoT endpoint to connect tocustomAuthConfig- - AWS IoT custom auth configuration- Returns:
- - A new AwsIotMqtt5ClientBuilder
-
newDirectMqttBuilderWithMtlsFromPkcs11
@Deprecated public static AwsIotMqtt5ClientBuilder newDirectMqttBuilderWithMtlsFromPkcs11(String hostName, String pkcs12Path, String pkcs12Password)
Deprecated.Use alternate newDirectMqttBuilderWithMtlsFromPkcs12(). Create a new builder with mTLS, using a PKCS12 library for private key operations. NOTE: MacOS only- Parameters:
hostName- - AWS IoT endpoint to connect topkcs12Path- Path to the PKCS12 file to use with the builder.pkcs12Password- The password of the PKCS12 file to use with the builder.- Returns:
- - A new AwsIotMqtt5ClientBuilder
-
newDirectMqttBuilderWithMtlsFromPkcs12
public static AwsIotMqtt5ClientBuilder newDirectMqttBuilderWithMtlsFromPkcs12(String hostName, String pkcs12Path, String pkcs12Password)
Create a new builder with mTLS, using a PKCS12 library for private key operations. NOTE: MacOS only- Parameters:
hostName- - AWS IoT endpoint to connect topkcs12Path- Path to the PKCS12 file to use with the builder.pkcs12Password- The password of the PKCS12 file to use with the builder.- Returns:
- - A new AwsIotMqtt5ClientBuilder
-
newWebsocketMqttBuilderWithSigv4Auth
public static AwsIotMqtt5ClientBuilder newWebsocketMqttBuilderWithSigv4Auth(String hostName, AwsIotMqtt5ClientBuilder.WebsocketSigv4Config config)
Create a new MQTT5 client builder that will use websockets and AWS Sigv4 signing to establish mutually-authenticated (mTLS) connections.- Parameters:
hostName- - AWS IoT endpoint to connect toconfig- - Additional Sigv4-oriented options to use- Returns:
- - A new AwsIotMqtt5ClientBuilder
-
newWebsocketMqttBuilderWithCustomAuth
public static AwsIotMqtt5ClientBuilder newWebsocketMqttBuilderWithCustomAuth(String hostName, AwsIotMqtt5ClientBuilder.MqttConnectCustomAuthConfig customAuthConfig)
Creates a new MQTT5 client builder that will use websocket connection and a custom authenticator controlled by the username and password values.- Parameters:
hostName- - AWS IoT endpoint to connect tocustomAuthConfig- - AWS IoT custom auth configuration- Returns:
- - A new AwsIotMqtt5ClientBuilder
-
newDirectMqttBuilderWithJavaKeystore
public static AwsIotMqtt5ClientBuilder newDirectMqttBuilderWithJavaKeystore(String hostName, KeyStore keyStore, String certificateAlias, String certificatePassword)
Creates a new MQTT5 client builder using a certificate and key stored in the passed-in Java keystore. Note: This function assumes the passed-in keystore has already been loaded from a file by callingkeystore.load(file, password).- Parameters:
hostName- AWS IoT endpoint to connect tokeyStore- The Java keystore to use. Assumed to be loaded with certificates and keyscertificateAlias- The alias of the certificate and key to use with the builder.certificatePassword- The password of the certificate and key to use with the builder.- Returns:
- A new AwsIotMqtt5ClientBuilder
-
newMqttBuilder
public static AwsIotMqtt5ClientBuilder newMqttBuilder(String hostName)
Creates a new MQTT5 client builder with default TLS options. This requires setting all connection details manually. Default port to direct MQTT.- Parameters:
hostName- - AWS IoT endpoint to connect to- Returns:
- - A new AwsIotMqtt5ClientBuilder
-
newMqttBuilderFromMqtt311ConnectionConfig
public static AwsIotMqtt5ClientBuilder newMqttBuilderFromMqtt311ConnectionConfig(software.amazon.awssdk.crt.mqtt.MqttConnectionConfig mqtt311Config, software.amazon.awssdk.crt.io.TlsContextOptions tlsOptions) throws Exception
Creates a new MQTT5 client builder using a MqttConnectionConfig. This does NOT support all MqttConnectionConfig options and will throw an exception should it encounter options it does not support. Known unsupported options/cases:- Custom Authorizer: Will not be properly detected nor setup
- Websockets: Is not supported and will throw an exception
- Will Message: Is not supported and will throw an exception
- All Callbacks: Connection callbacks are not supported and will be ignored
- Parameters:
mqtt311Config- The MqttConnectionConfig to create a MQTT5 client builder fromtlsOptions- The TLS options to use alongside the MqttConnectionConfig- Returns:
- A new AwsIotMqtt5ClientBuilder
- Throws:
Exception- If an unsupported option is passed
-
withCertificateAuthorityFromPath
public AwsIotMqtt5ClientBuilder withCertificateAuthorityFromPath(String caDirPath, String caFilePath)
Overrides the default system trust store.- Parameters:
caDirPath- - Only used on Unix-style systems where all trust anchors are stored in a directory (e.g. /etc/ssl/certs).caFilePath- - Single file containing all trust CAs, in PEM format.- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withCertificateAuthority
public AwsIotMqtt5ClientBuilder withCertificateAuthority(String caRoot)
Overrides the default trust store.- Parameters:
caRoot- - Buffer containing all trust CAs, in PEM format.- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withPort
public AwsIotMqtt5ClientBuilder withPort(Long port)
Overrides the port to connect to on the IoT endpoint- Parameters:
port- - The port to connect to on the IoT endpoint. Usually 8883 for MQTT, or 443 for websockets- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withConnectProperties
public AwsIotMqtt5ClientBuilder withConnectProperties(software.amazon.awssdk.crt.mqtt5.packets.ConnectPacket.ConnectPacketBuilder connectPacket)
Overrides all configurable options with respect to the CONNECT packet sent by the client, including the will. These connect properties will be used for every connection attempt made by the client. Custom authentication configuration will override the username and password values in this configuration.- Parameters:
connectPacket- - All configurable options with respect to the CONNECT packet sent by the client- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withSessionBehavior
public AwsIotMqtt5ClientBuilder withSessionBehavior(software.amazon.awssdk.crt.mqtt5.Mqtt5ClientOptions.ClientSessionBehavior sessionBehavior)
Overrides how the MQTT5 client should behave with respect to MQTT sessions.- Parameters:
sessionBehavior- - How the MQTT5 client should behave with respect to MQTT sessions.- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withRetryJitterMode
public AwsIotMqtt5ClientBuilder withRetryJitterMode(software.amazon.awssdk.crt.io.ExponentialBackoffRetryOptions.JitterMode jitterMode)
Overrides how the reconnect delay is modified in order to smooth out the distribution of reconnect attempt time points for a large set of reconnecting clients.- Parameters:
jitterMode- - Controls how the reconnect delay is modified in order to smooth out the distribution of reconnect attempt time points for a large set of reconnecting clients.- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withMinReconnectDelayMs
public AwsIotMqtt5ClientBuilder withMinReconnectDelayMs(Long minReconnectDelayMs)
Overrides the minimum amount of time to wait to reconnect after a disconnect. Exponential back-off is performed with controllable jitter after each connection failure.- Parameters:
minReconnectDelayMs- - Minimum amount of time to wait to reconnect after a disconnect.- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withMaxReconnectDelayMs
public AwsIotMqtt5ClientBuilder withMaxReconnectDelayMs(Long maxReconnectDelayMs)
Overrides the maximum amount of time to wait to reconnect after a disconnect. Exponential back-off is performed with controllable jitter after each connection failure.- Parameters:
maxReconnectDelayMs- - Maximum amount of time to wait to reconnect after a disconnect.- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withMinConnectedTimeToResetReconnectDelayMs
public AwsIotMqtt5ClientBuilder withMinConnectedTimeToResetReconnectDelayMs(Long minConnectedTimeToResetReconnectDelayMs)
Overrides the amount of time that must elapse with an established connection before the reconnect delay is reset to the minimum. This helps alleviate bandwidth-waste in fast reconnect cycles due to permission failures on operations.- Parameters:
minConnectedTimeToResetReconnectDelayMs- - The amount of time that must elapse with an established connection before the reconnect delay is reset to the minimum.- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withConnackTimeoutMs
public AwsIotMqtt5ClientBuilder withConnackTimeoutMs(Long connackTimeoutMs)
Overrides the time interval to wait after sending a CONNECT request for a CONNACK to arrive. If one does not arrive, the connection will be shut down.- Parameters:
connackTimeoutMs- - The time interval to wait after sending a CONNECT request for a CONNACK to arrive.- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withOfflineQueueBehavior
public AwsIotMqtt5ClientBuilder withOfflineQueueBehavior(software.amazon.awssdk.crt.mqtt5.Mqtt5ClientOptions.ClientOfflineQueueBehavior offlineQueueBehavior)
Overrides how disconnects affect the queued and in-progress operations tracked by the client. Also controls how new operations are handled while the client is not connected. In particular, if the client is not connected, then any operation that would be failed on disconnect (according to these rules) will also be rejected.- Parameters:
offlineQueueBehavior- - How disconnects affect the queued and in-progress operations tracked by the client.- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withPingTimeoutMs
public AwsIotMqtt5ClientBuilder withPingTimeoutMs(Long pingTimeoutMs)
Overrides the time interval to wait after sending a PINGREQ for a PINGRESP to arrive. If one does not arrive, the client will close the current connection.- Parameters:
pingTimeoutMs- - The time interval to wait after sending a PINGREQ for a PINGRESP to arrive.- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withAckTimeoutSeconds
public AwsIotMqtt5ClientBuilder withAckTimeoutSeconds(Long ackTimeoutSeconds)
Overrides the time interval to wait for an ack after sending a QoS 1+ PUBLISH, SUBSCRIBE, or UNSUBSCRIBE before failing the operation. Defaults to no timeout.- Parameters:
ackTimeoutSeconds- - the time interval to wait for an ack after sending a QoS 1+ PUBLISH, SUBSCRIBE, or UNSUBSCRIBE before failing the operation- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withSocketOptions
public AwsIotMqtt5ClientBuilder withSocketOptions(software.amazon.awssdk.crt.io.SocketOptions socketOptions)
Overrides the socket properties of the underlying MQTT connections made by the client. Leave undefined to use defaults (no TCP keep alive, 10 second socket timeout).- Parameters:
socketOptions- - The socket properties of the underlying MQTT connections made by the client- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withHttpProxyOptions
public AwsIotMqtt5ClientBuilder withHttpProxyOptions(software.amazon.awssdk.crt.http.HttpProxyOptions httpProxyOptions)
Overrides (tunneling) HTTP proxy usage when establishing MQTT connections.- Parameters:
httpProxyOptions- - HTTP proxy options to use when establishing MQTT connections.- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withExtendedValidationAndFlowControlOptions
public AwsIotMqtt5ClientBuilder withExtendedValidationAndFlowControlOptions(software.amazon.awssdk.crt.mqtt5.Mqtt5ClientOptions.ExtendedValidationAndFlowControlOptions extendedValidationAndFlowControlOptions)
Overrides additional controls for client behavior with respect to operation validation and flow control; these checks go beyond the base MQTT5 spec to respect limits of specific MQTT brokers.- Parameters:
extendedValidationAndFlowControlOptions- - additional controls for client behavior with respect to operation validation and flow control- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withLifeCycleEvents
public AwsIotMqtt5ClientBuilder withLifeCycleEvents(software.amazon.awssdk.crt.mqtt5.Mqtt5ClientOptions.LifecycleEvents lifecycleEvents)
Sets the LifeCycleEvents that will be called by the client when receives a life cycle events. Examples of life cycle events are: Connection success, connection failure, disconnection, etc.- Parameters:
lifecycleEvents- - The LifeCycleEvents to be called- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withPublishEvents
public AwsIotMqtt5ClientBuilder withPublishEvents(software.amazon.awssdk.crt.mqtt5.Mqtt5ClientOptions.PublishEvents publishEvents)
Sets the PublishEvents that will be called by the client when it receives a publish packet.- Parameters:
publishEvents- The PublishEvents to be called- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withTopicAliasingOptions
public AwsIotMqtt5ClientBuilder withTopicAliasingOptions(software.amazon.awssdk.crt.mqtt5.TopicAliasingOptions options)
Overrides how the MQTT5 client should behave with respect to MQTT5 topic aliasing.- Parameters:
options- - How the MQTT5 client should use topic aliasing- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withMinimumTlsVersion
public AwsIotMqtt5ClientBuilder withMinimumTlsVersion(software.amazon.awssdk.crt.io.TlsContextOptions.TlsVersions minimumTlsVersion)
Sets the minimum TLS version that is acceptable for connection establishment.- Parameters:
minimumTlsVersion- - Minimum TLS version allowed in client connections.- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withTlsCipherPreference
public AwsIotMqtt5ClientBuilder withTlsCipherPreference(software.amazon.awssdk.crt.io.TlsCipherPreference tlsCipherPreference)
Sets the TLS cipher preference.Note: Setting a custom TLS cipher preference is supported only on Unix-like platforms (e.g., Linux, Android) when using the s2n library. Other platforms currently support only `TLS_CIPHER_SYSTEM_DEFAULT`.
- Parameters:
tlsCipherPreference- - The TLS cipher preference to use.- Returns:
- - The AwsIotMqtt5ClientBuilder
-
withKeepAliveIntervalSeconds
public AwsIotMqtt5ClientBuilder withKeepAliveIntervalSeconds(Long keepAliveIntervalSeconds)
Sets the maximum time interval, in seconds, that is permitted to elapse between the point at which the client finishes transmitting one MQTT packet and the point it starts sending the next. The client will use PINGREQ packets to maintain this property. If the responding ConnAckPacket contains a keep alive property value, then that is the negotiated keep alive value. Otherwise, the keep alive sent by the client is the negotiated value. See MQTT5 Keep Alive NOTE: The keepAliveIntervalSeconds HAS to be larger than the pingTimeoutMs time set in the Mqtt5ClientOptions.- Parameters:
keepAliveIntervalSeconds- the maximum time interval, in seconds, that is permitted to elapse between the point at which the client finishes transmitting one MQTT packet and the point it starts sending the next.- Returns:
- The AwsIotMqtt5ClientBuilder after setting the keep alive interval.
-
withClientId
public AwsIotMqtt5ClientBuilder withClientId(String clientId)
Sets the unique string identifying the client to the server. Used to restore session state between connections. If left empty, the broker will auto-assign a unique client id. When reconnecting, the Mqtt5Client will always use the auto-assigned client id. See MQTT5 Client Identifier- Parameters:
clientId- A unique string identifying the client to the server.- Returns:
- The AwsIotMqtt5ClientBuilder after setting the client ID.
-
withSessionExpiryIntervalSeconds
public AwsIotMqtt5ClientBuilder withSessionExpiryIntervalSeconds(Long sessionExpiryIntervalSeconds)
Sets the time interval, in seconds, that the client requests the server to persist this connection's MQTT session state for. Has no meaning if the client has not been configured to rejoin sessions. Must be non-zero in order to successfully rejoin a session. If the responding ConnAckPacket contains a session expiry property value, then that is the negotiated session expiry value. Otherwise, the session expiry sent by the client is the negotiated value. See MQTT5 Session Expiry Interval- Parameters:
sessionExpiryIntervalSeconds- A time interval, in seconds, that the client requests the server to persist this connection's MQTT session state for.- Returns:
- The AwsIotMqtt5ClientBuilder after setting the session expiry interval.
-
withRequestResponseInformation
public AwsIotMqtt5ClientBuilder withRequestResponseInformation(Boolean requestResponseInformation)
Sets whether requests that the server send response information in the subsequent ConnAckPacket. This response information may be used to set up request-response implementations over MQTT, but doing so is outside the scope of the MQTT5 spec and client. See MQTT5 Request Response Information- Parameters:
requestResponseInformation- If true, requests that the server send response information in the subsequent ConnAckPacket.- Returns:
- The AwsIotMqtt5ClientBuilder after setting the request response information.
-
withRequestProblemInformation
public AwsIotMqtt5ClientBuilder withRequestProblemInformation(Boolean requestProblemInformation)
Sets whether requests that the server send additional diagnostic information (via response string or user properties) in DisconnectPacket or ConnAckPacket from the server. See MQTT5 Request Problem Information- Parameters:
requestProblemInformation- If true, requests that the server send additional diagnostic information (via response string or user properties) in DisconnectPacket or ConnAckPacket from the server.- Returns:
- The AwsIotMqtt5ClientBuilder after setting the request problem information.
-
withReceiveMaximum
public AwsIotMqtt5ClientBuilder withReceiveMaximum(Long receiveMaximum)
Sets the maximum number of in-flight QoS 1 and 2 messages the client is willing to handle. If omitted or null, then no limit is requested. See MQTT5 Receive Maximum- Parameters:
receiveMaximum- The maximum number of in-flight QoS 1 and 2 messages the client is willing to handle.- Returns:
- The AwsIotMqtt5ClientBuilder after setting the receive maximum.
-
withMaximumPacketSizeBytes
public AwsIotMqtt5ClientBuilder withMaximumPacketSizeBytes(Long maximumPacketSizeBytes)
Sets the maximum packet size the client is willing to handle. If omitted or null, then no limit beyond the natural limits of MQTT packet size is requested. See MQTT5 Maximum Packet Size- Parameters:
maximumPacketSizeBytes- The maximum packet size the client is willing to handle- Returns:
- The AwsIotMqtt5ClientBuilder after setting the maximum packet size.
-
withWillDelayIntervalSeconds
public AwsIotMqtt5ClientBuilder withWillDelayIntervalSeconds(Long willDelayIntervalSeconds)
Sets the time interval, in seconds, that the server should wait (for a session reconnection) before sending the will message associated with the connection's session. If omitted or null, the server will send the will when the associated session is destroyed. If the session is destroyed before a will delay interval has elapsed, then the will must be sent at the time of session destruction. See MQTT5 Will Delay Interval- Parameters:
willDelayIntervalSeconds- A time interval, in seconds, that the server should wait (for a session reconnection) before sending the will message associated with the connection's session.- Returns:
- The AwsIotMqtt5ClientBuilder after setting the will message delay interval.
-
withWill
public AwsIotMqtt5ClientBuilder withWill(software.amazon.awssdk.crt.mqtt5.packets.PublishPacket will)
Sets the definition of a message to be published when the connection's session is destroyed by the server or when the will delay interval has elapsed, whichever comes first. If null, then nothing will be sent. See MQTT5 Will- Parameters:
will- The message to be published when the connection's session is destroyed by the server or when the will delay interval has elapsed, whichever comes first.- Returns:
- The AwsIotMqtt5ClientBuilder after setting the will message.
-
withUserProperties
public AwsIotMqtt5ClientBuilder withUserProperties(List<software.amazon.awssdk.crt.mqtt5.packets.UserProperty> userProperties)
Sets the list of MQTT5 user properties included with the packet. See MQTT5 User Property- Parameters:
userProperties- List of MQTT5 user properties included with the packet.- Returns:
- The AwsIotMqtt5ClientBuilder after setting the user properties.
-
build
public software.amazon.awssdk.crt.mqtt5.Mqtt5Client build()
Constructs an MQTT5 client object configured with the options set.- Returns:
- A MQTT5ClientOptions
-
extractRegionFromEndpoint
public static String extractRegionFromEndpoint(String endpoint) throws Exception
Attempts to determine the AWS region associated with an endpoint. Will throw an exception if it cannot find the region.- Parameters:
endpoint- - The endpoint to compute the region for.- Returns:
- The region associated with the endpoint.
- Throws:
Exception- When AWS region cannot be extracted from endpoint.
-
-