Last active
September 23, 2018 14:52
-
-
Save amanjeetsingh150/4f15aff0050a3ef367dd95148b8ceea1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void connect() { | |
MqttConnectOptions mqttConnectOptions = new MqttConnectOptions(); | |
mqttConnectOptions.setAutomaticReconnect(true); | |
mqttConnectOptions.setCleanSession(false); | |
mqttConnectOptions.setUserName(username); | |
mqttConnectOptions.setPassword(password.toCharArray()); | |
try { | |
mqttAndroidClient.connect(mqttConnectOptions, null, new IMqttActionListener() { | |
@Override | |
public void onSuccess(IMqttToken asyncActionToken) { | |
DisconnectedBufferOptions disconnectedBufferOptions = new DisconnectedBufferOptions(); | |
disconnectedBufferOptions.setBufferEnabled(true); | |
disconnectedBufferOptions.setBufferSize(100); | |
disconnectedBufferOptions.setPersistBuffer(false); | |
disconnectedBufferOptions.setDeleteOldestMessages(false); | |
mqttAndroidClient.setBufferOpts(disconnectedBufferOptions); | |
subscribeToTopic(); | |
} | |
@Override | |
public void onFailure(IMqttToken asyncActionToken, Throwable exception) { | |
Log.d(TAG, "Failed to connect to: " + serverUri + exception.toString()); | |
} | |
}); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment