public class AWSIotMqttManager
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.Integer |
DEFAULT_AUTO_RECONNECT_ATTEMPTS
Default value for number of auto reconnect attempts before giving up.
|
static java.lang.Boolean |
DEFAULT_AUTO_RECONNECT_ENABLED
Default value for reconnect enabled.
|
static java.lang.Integer |
DEFAULT_KEEP_ALIVE_SECONDS
Default value for MQTT keep alive.
|
static java.lang.Integer |
DEFAULT_MAX_RECONNECT_RETRY_TIME_SECONDS
Default value for maximum delay in exponential backoff reconnect algorithm.
|
static java.lang.Integer |
DEFAULT_MIN_RECONNECT_RETRY_TIME_SECONDS
Default value for starting delay in exponential backoff reconnect algorithm.
|
static java.lang.Integer |
DEFAULT_OFFLINE_PUBLISH_QUEUE_BOUND
Default value for offline publish queue bound.
|
static java.lang.Boolean |
DEFAULT_OFFLINE_PUBLISH_QUEUE_ENABLED
Default value for offline publish queue enabled.
|
Constructor and Description |
---|
AWSIotMqttManager(java.lang.String mqttClientId,
Region region,
java.lang.String accountEndpointPrefix)
Constructs a new AWSIotMqttManager.
|
AWSIotMqttManager(java.lang.String mqttClientId,
java.lang.String endpoint)
Constructs a new AWSIotMqttManager.
|
Modifier and Type | Method and Description |
---|---|
void |
addUserMetaData(java.util.Map<java.lang.String,java.lang.String> userMetaDataMap)
Deprecated.
Since 2.13.2 this method will be removed in the next minor version.
Please use updateUserMetaData method instead.
Sets the userMetaData map.
|
void |
connect(AWSCredentialsProvider credentialsProvider,
AWSIotMqttClientStatusCallback statusCallback)
Initializes the MQTT session and connects to the specified MQTT server
using AWS credentials.
|
void |
connect(java.security.KeyStore keyStore,
AWSIotMqttClientStatusCallback statusCallback)
Initializes the MQTT session and connects to the specified MQTT server
using certificate and private key in keystore on port 8883.
|
void |
connectUsingALPN(java.security.KeyStore keyStore,
AWSIotMqttClientStatusCallback statusCallback)
Initializes the MQTT session and connects to the specified MQTT server
using certificate and private key in keystore on port 443.
|
void |
connectWithProxy(java.security.KeyStore keyStore,
java.lang.String proxyHost,
int proxyPort,
AWSIotMqttClientStatusCallback statusCallback)
Initializes the MQTT session and connects to the specified MQTT server
using certificate and private key in keystore on port 8883 via the proxy specified by a
host and port combination.
|
boolean |
disconnect()
Disconnect from a mqtt client (close current MQTT session).
|
boolean |
fullPublishQueueKeepsOldestMessages()
Keep the oldest messages when publish queue is full?
|
java.lang.String |
getAccountEndpointPrefix()
Return the customer specific endpoint prefix.
|
int |
getConnectionStabilityTime()
Gets the connection established time.
|
java.lang.Long |
getDrainingInterval()
Get the "draining interval" (the time between publish messages are sent from the offline queue when reconnected).
|
int |
getKeepAlive()
Get the MQTT keep alive time.
|
int |
getMaxAutoReconnectAttempts()
Get the current setting of maximum reconnects attempted automatically before quitting.
|
int |
getMaxReconnectRetryTime()
Gets the current maximum value for time to wait between autoreconnect attempts.
|
int |
getMinReconnectRetryTime()
Gets the current starting value for time to wait between autoreconnect attempts.
|
AWSIotMqttLastWillAndTestament |
getMqttLastWillAndTestament()
Get the currently configured Last Will and Testament.
|
java.lang.Integer |
getOfflinePublishQueueBound()
Get the current value of the offline message queue bound.
|
int |
getReconnectTimeout()
Deprecated.
|
boolean |
isAutoReconnect()
Is auto-reconnect enabled?
|
boolean |
isMetricsEnabled() |
boolean |
isOfflinePublishQueueEnabled()
Is the publish queue while offline feature enabled?
|
void |
publishData(byte[] data,
java.lang.String topic,
AWSIotMqttQos qos)
Publish data to an MQTT topic.
|
void |
publishData(byte[] data,
java.lang.String topic,
AWSIotMqttQos qos,
AWSIotMqttMessageDeliveryCallback callback,
java.lang.Object userData)
Publish data to an MQTT topic.
|
void |
publishString(java.lang.String str,
java.lang.String topic,
AWSIotMqttQos qos)
Send a message to an MQTT topic.
|
void |
publishString(java.lang.String str,
java.lang.String topic,
AWSIotMqttQos qos,
AWSIotMqttMessageDeliveryCallback cb,
java.lang.Object userData)
Send a message to an MQTT topic.
|
void |
resetReconnect()
Reset the backoff logic to the initial values.
|
void |
setAutoReconnect(boolean enabled)
Enable / disable the auto-reconnect feature.
|
void |
setAutoResubscribe(boolean enabled)
Enable/Disable auto resubscribe feature.
|
void |
setCleanSession(boolean cleanSession)
Set to true if the connection should be established with a clean session, false otherwise.
|
void |
setConnectionStabilityTime(int time)
Sets the connection stability time.
|
void |
setCredentialsProvider(AWSCredentialsProvider credentialsProvider)
Set the AWS credentials provider to be used in SigV4 MQTT connections.
|
void |
setDrainingInterval(java.lang.Long interval)
Set the "draining interval" (the time between publish messages are sent from the offline queue when reconnected).
|
void |
setFullQueueToKeepNewestMessages()
Set the queue behavior on a full queue to keep newest messages.
|
void |
setFullQueueToKeepOldestMessages()
Set the queue behavior on a full queue to keep oldest messages.
|
void |
setKeepAlive(int keepAlive)
Sets the MQTT keep alive time used by the underlying MQTT client to
determine connection status.
|
void |
setMaxAutoReconnectAttempts(int attempts)
Set the maximum reconnects attempted automatically before quitting.
|
void |
setMaxAutoReconnectAttepts(int attempts)
Deprecated.
Please use
setMaxAutoReconnectAttempts(int) instead. |
void |
setMetricsIsEnabled(boolean enabled)
Turning on/off metrics collection.
|
void |
setMqttLastWillAndTestament(AWSIotMqttLastWillAndTestament lwt)
Set the client last will and testament.
|
void |
setOfflinePublishQueueBound(java.lang.Integer bound)
Set the bound for the number of messages queued while offline.
|
void |
setOfflinePublishQueueEnabled(boolean enabled)
Enable or disable offline publish queueing.
|
void |
setReconnectRetryLimits(int minTimeout,
int maxTimeout)
Sets the times to wait between autoreconnect attempts.
|
void |
setReconnectTimeout(int timeout)
Deprecated.
|
void |
subscribeToTopic(java.lang.String topic,
AWSIotMqttQos qos,
AWSIotMqttNewMessageCallback callback)
Subscribes to an MQTT topic.
|
void |
subscribeToTopic(java.lang.String topic,
AWSIotMqttQos qos,
AWSIotMqttSubscriptionStatusCallback subscriptionStatusCallback,
AWSIotMqttNewMessageCallback callback)
Subscribes to an MQTT topic
|
void |
unsubscribeTopic(java.lang.String topic)
Unsubscribe from an MQTT topic.
|
void |
updateUserMetaData(java.util.Map<java.lang.String,java.lang.String> userMetaDataMap)
This is an internal method.
|
public static final java.lang.Integer DEFAULT_MIN_RECONNECT_RETRY_TIME_SECONDS
public static final java.lang.Integer DEFAULT_MAX_RECONNECT_RETRY_TIME_SECONDS
public static final java.lang.Boolean DEFAULT_AUTO_RECONNECT_ENABLED
public static final java.lang.Integer DEFAULT_AUTO_RECONNECT_ATTEMPTS
public static final java.lang.Integer DEFAULT_KEEP_ALIVE_SECONDS
public static final java.lang.Boolean DEFAULT_OFFLINE_PUBLISH_QUEUE_ENABLED
public static final java.lang.Integer DEFAULT_OFFLINE_PUBLISH_QUEUE_BOUND
public AWSIotMqttManager(java.lang.String mqttClientId, java.lang.String endpoint)
mqttClientId
- MQTT client ID to use with this client.endpoint
- AWS IoT endpoint.
Expected endpoint formats:
XXXXXXX.iot.[region].amazonaws.com or
XXXXXXX-ats.iot.[region].amazonaws.com or
XXXXXXX.ats.iot.cn-north-1.amazonaws.com.cnpublic AWSIotMqttManager(java.lang.String mqttClientId, Region region, java.lang.String accountEndpointPrefix)
mqttClientId
- MQTT client ID to use with this client.region
- The AWS region to use when creating endpoint.accountEndpointPrefix
- Customer specific endpont prefix XXXXXXX in
XXXXXXX.iot.[region].amazonaws.com or
XXXXXXX-ats.iot.[region].amazonaws.com or
XXXXXXX.ats.iot.cn-north-1.amazonaws.com.cnpublic void setMetricsIsEnabled(boolean enabled)
enabled
- indicates whether metrics collection is enabled or disabled.public boolean isMetricsEnabled()
@Deprecated public void addUserMetaData(java.util.Map<java.lang.String,java.lang.String> userMetaDataMap)
userMetaDataMap
- userMetaData mappublic void updateUserMetaData(java.util.Map<java.lang.String,java.lang.String> userMetaDataMap)
userMetaDataMap
- userMetaData mappublic java.lang.String getAccountEndpointPrefix()
public boolean isAutoReconnect()
public void setAutoReconnect(boolean enabled)
enabled
- true if enabled, false if disabled.@Deprecated public int getReconnectTimeout()
@Deprecated public void setReconnectTimeout(int timeout)
timeout
- timeout value in seconds.public void setReconnectRetryLimits(int minTimeout, int maxTimeout)
minTimeout
- minimum timeout value in seconds.maxTimeout
- maximum timeout value in seconds.public int getMinReconnectRetryTime()
public int getMaxReconnectRetryTime()
public int getMaxAutoReconnectAttempts()
@Deprecated public void setMaxAutoReconnectAttepts(int attempts)
setMaxAutoReconnectAttempts(int)
instead.attempts
- number of reconnects attempted automatically. Retry forever =
-1.public void setMaxAutoReconnectAttempts(int attempts)
attempts
- number of reconnects attempted automatically. Retry
forever = -1.public void setConnectionStabilityTime(int time)
time
- time to wait to declare a connection to be stable (in seconds).public int getConnectionStabilityTime()
public boolean isOfflinePublishQueueEnabled()
public void setOfflinePublishQueueEnabled(boolean enabled)
enabled
- boolean queueing feature is enabled.public java.lang.Integer getOfflinePublishQueueBound()
public void setOfflinePublishQueueBound(java.lang.Integer bound)
bound
- max number of messages to queue while offline. Negative or 0
values ignored.public java.lang.Long getDrainingInterval()
public void setDrainingInterval(java.lang.Long interval)
interval
- milliseconds between offline queue publishes.public boolean fullPublishQueueKeepsOldestMessages()
public void setFullQueueToKeepOldestMessages()
public void setFullQueueToKeepNewestMessages()
public int getKeepAlive()
public void setKeepAlive(int keepAlive)
keepAlive
- the MQTT keep alive time set by the user (in seconds). A
value of 0 disables keep alive.public AWSIotMqttLastWillAndTestament getMqttLastWillAndTestament()
public void setMqttLastWillAndTestament(AWSIotMqttLastWillAndTestament lwt)
lwt
- the desired last will and testament.public void setCredentialsProvider(AWSCredentialsProvider credentialsProvider)
credentialsProvider
- AWS credentials provider used to create the MQTT connection.public void setAutoResubscribe(boolean enabled)
enabled
- Indicate whether auto resubscribe feature is enabled.public void setCleanSession(boolean cleanSession)
cleanSession
- flag to establish a clean sessionpublic void connectUsingALPN(java.security.KeyStore keyStore, AWSIotMqttClientStatusCallback statusCallback)
keyStore
- A keystore containing an keystore with a certificate and
private key. Use IotKeystoreHelper to get keystore.statusCallback
- When new MQTT session status is received the
function of callback will be called with new connection
status.public void connectWithProxy(java.security.KeyStore keyStore, java.lang.String proxyHost, int proxyPort, AWSIotMqttClientStatusCallback statusCallback)
AWSIotKeystoreHelper
to setup the
certificate and key aliases as expected by the underlying socket helper library.keyStore
- A keystore containing an keystore with a certificate and
private key. Use IotKeystoreHelper to get keystore.proxyHost
- hostname of the proxyproxyPort
- proxy port numberstatusCallback
- When new MQTT session status is received the
function of callback will be called with new connection
status.public void connect(java.security.KeyStore keyStore, AWSIotMqttClientStatusCallback statusCallback)
AWSIotKeystoreHelper
to setup the certificate and key aliases as
expected by the underlying socket helper library.keyStore
- A keystore containing an keystore with a certificate and
private key. Use IotKeystoreHelper to get keystore.statusCallback
- When new MQTT session status is received the
function of callback will be called with new connection
status.public void connect(AWSCredentialsProvider credentialsProvider, AWSIotMqttClientStatusCallback statusCallback)
credentialsProvider
- AWS credentialsProvider used to create a WebSocket connection to AWS IoT.statusCallback
- When new MQTT session status is received the function of callback will
be called with new connection status.public boolean disconnect()
public void resetReconnect()
public void subscribeToTopic(java.lang.String topic, AWSIotMqttQos qos, AWSIotMqttNewMessageCallback callback)
topic
- The topic to which to subscribe.qos
- Quality of Service Level of the subscription.callback
- Callback to be called when new message is received on
this topic for this subscription.public void subscribeToTopic(java.lang.String topic, AWSIotMqttQos qos, AWSIotMqttSubscriptionStatusCallback subscriptionStatusCallback, AWSIotMqttNewMessageCallback callback)
topic
- The topic to which to subscribe.qos
- Quality of Service Level of the subscription.subscriptionStatusCallback
- Callback that will be notified when the subscribe has completed.
Any exception encountered during the subscribe operation is reported on the callback
if avalialble, else AmazonClientException is thrown by this method.callback
- Callback to be called when new message is received on this
topic for this subscription.public void unsubscribeTopic(java.lang.String topic)
topic
- topic from which to unsubscribe.public void publishString(java.lang.String str, java.lang.String topic, AWSIotMqttQos qos)
str
- The message payload to be sent (as a String).topic
- The topic on which to publish.qos
- The quality of service requested for this message.public void publishString(java.lang.String str, java.lang.String topic, AWSIotMqttQos qos, AWSIotMqttMessageDeliveryCallback cb, java.lang.Object userData)
str
- The message payload to be sent (as a String).topic
- The topic on which to publish.qos
- The quality of service requested for this message.cb
- Callback for message status.userData
- User defined data which will be passed back to the user when the
callback is invoked.public void publishData(byte[] data, java.lang.String topic, AWSIotMqttQos qos)
data
- The message payload to be sent as a byte array.topic
- The topic on which to publish.qos
- The quality of service requested for this message.public void publishData(byte[] data, java.lang.String topic, AWSIotMqttQos qos, AWSIotMqttMessageDeliveryCallback callback, java.lang.Object userData)
data
- The message payload to be sent as a byte array.topic
- The topic on which to publish.qos
- The quality of service requested for this message.callback
- Callback for message status.userData
- User defined data which will be passed back to the user when the
callback is invoked.Copyright © 2018 Amazon Web Services, Inc. All Rights Reserved.