public class AWSIotMqttManager extends Object
| Modifier and Type | Field and Description |
|---|---|
static Integer |
DEFAULT_AUTO_RECONNECT_ATTEMPTS
Default value for number of auto reconnect attempts before giving up.
|
static Boolean |
DEFAULT_AUTO_RECONNECT_ENABLED
Default value for reconnect enabled.
|
static Integer |
DEFAULT_KEEP_ALIVE_SECONDS
Default value for MQTT keep alive.
|
static Integer |
DEFAULT_MAX_RECONNECT_RETRY_TIME_SECONDS
Default value for maximum delay in exponential backoff reconnect algorithm.
|
static Integer |
DEFAULT_MIN_RECONNECT_RETRY_TIME_SECONDS
Default value for starting delay in exponential backoff reconnect algorithm.
|
static Integer |
DEFAULT_OFFLINE_PUBLISH_QUEUE_BOUND
Default value for offline publish queue bound.
|
static Boolean |
DEFAULT_OFFLINE_PUBLISH_QUEUE_ENABLED
Default value for offline publish queue enabled.
|
| Constructor and Description |
|---|
AWSIotMqttManager(String mqttClientId,
Region region,
String accountEndpointPrefix)
Constructs a new AWSIotMqttManager.
|
| Modifier and Type | Method and Description |
|---|---|
void |
connect(KeyStore keyStore,
AWSIotMqttClientStatusCallback statusCallback)
Initializes the MQTT session and connects to the specified MQTT server
using certificate and private key in keystore.
|
boolean |
disconnect()
Disconnect from a mqtt client (close current MQTT session).
|
boolean |
fullPublishQueueKeepsOldestMessages()
Keep the oldest messages when publish queue is full?
|
String |
getAccountEndpointPrefix()
Return the customer specific endpoint prefix.
|
int |
getConnectionStabilityTime()
Gets the connection established time.
|
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.
|
Integer |
getOfflinePublishQueueBound()
Get the current value of the offline message queue bound.
|
int |
getReconnectTimeout()
Deprecated.
|
boolean |
isAutoReconnect()
Is auto-reconnect enabled?
|
boolean |
isOfflinePublishQueueEnabled()
Is the publish queue while offline feature enabled?
|
void |
publishData(byte[] data,
String topic,
AWSIotMqttQos qos)
Publish data to an MQTT topic.
|
void |
publishString(String str,
String topic,
AWSIotMqttQos qos)
Send a message to an MQTT topic.
|
void |
resetReconnect()
Reset the backoff logic to the inital values.
|
void |
setAutoReconnect(boolean enabled)
Enable / disable the auto-reconnect feature.
|
void |
setConnectionStabilityTime(int time)
Sets the connection stability time.
|
void |
setDrainingInterval(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 |
setMaxAutoReconnectAttepts(int attempts)
Set the maxium reconnects attempted automatically before quitting.
|
void |
setMqttLastWillAndTestament(AWSIotMqttLastWillAndTestament lwt)
Set the client last will and testament.
|
void |
setOfflinePublishQueueBound(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(String topic,
AWSIotMqttQos qos,
AWSIotMqttNewMessageCallback callback)
Subscribes to an MQTT topic.
|
void |
unsubscribeTopic(String topic)
Unsubscribe from an MQTT topic.
|
public static final Integer DEFAULT_MIN_RECONNECT_RETRY_TIME_SECONDS
public static final Integer DEFAULT_MAX_RECONNECT_RETRY_TIME_SECONDS
public static final Boolean DEFAULT_AUTO_RECONNECT_ENABLED
public static final Integer DEFAULT_AUTO_RECONNECT_ATTEMPTS
public static final Integer DEFAULT_KEEP_ALIVE_SECONDS
public static final Boolean DEFAULT_OFFLINE_PUBLISH_QUEUE_ENABLED
public static final Integer DEFAULT_OFFLINE_PUBLISH_QUEUE_BOUND
public AWSIotMqttManager(String mqttClientId, Region region, 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
XXXXXX.iot.[region].amazonaws.com.public 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()
public void setMaxAutoReconnectAttepts(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 Integer getOfflinePublishQueueBound()
public void setOfflinePublishQueueBound(Integer bound)
bound - max number of messages to queue while offline. Negative or 0
values ignored.public Long getDrainingInterval()
public void setDrainingInterval(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 connect(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 boolean disconnect()
public void resetReconnect()
public void subscribeToTopic(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 unsubscribeTopic(String topic)
topic - topic from which to unsubscribe.public void publishString(String str, 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 publishData(byte[] data,
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.Copyright © 2016. All rights reserved.