java - AWSIotMqttManager:onFailure:连接失败。MqttException (0) - java.io.IOException: 已经连接
问题描述
我目前正在使用 Android Studio 开发一个移动应用程序,该应用程序应该通过 AWS Cognito 进行身份验证,我使用 AWS Amplify 进行验证。Amplify 似乎工作正常,但是当我尝试连接到我的 Greengrass 事物的设备影子时,我从这个问题的标题中得到了错误:
AWSIotMqttManager:onFailure:连接失败。MqttException (0) - java.io.IOException: 已经连接
这很奇怪,因为我还没有调用连接命令,所以我不应该连接。
这是我的代码:
// Here I get the credentials which I later use to connect to AWSIoT
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(), // get the context for the current activity
"*****", // your AWS Account id
"us-east-2:****************", // your identity pool id
"arn:aws:iam::*************-unauthRole",// an authenticated role ARN
"arn:aws:iam::*************-authRole", // an unauthenticated role ARN
Regions.US_EAST_2 //Region
);
//Here I create the AWSIotMqttManager
AWSIotMqttManager awsIotMqttManager = new AWSIotMqttManager(uuidAsString,"endpoint");
//then I connect it
try {
awsIotMqttManager.connect(credentialsProvider, new AWSIotMqttClientStatusCallback() {
@Override
public void onStatusChanged(AWSIotMqttClientStatus status, Throwable throwable) {
if (status == AWSIotMqttClientStatus.Connected) {
awsIotMqttManager.subscribeToTopic("$aws/things/thing/shadow/update/documents", AWSIotMqttQos.QOS0, new AWSIotMqttNewMessageCallback() {
@Override
public void onMessageArrived(String topic, byte[] data) {
System.out.println("TOPIC: " + topic);
System.out.println(data);
}
});
String message = "{ \"state\": {\"desired\": {\"message\": \"Hello from ANDROID SDK\"} } }} }";
awsIotMqttManager.publishString(message,"$aws/things/thing/shadow/update",AWSIotMqttQos.QOS0);
}
});
}
catch (Exception e) {
Log.i("CHECK", e.toString());
}
解决方案
推荐阅读
- ckeditor - CKEditor image2 改变初始大小
- javascript - 绑定功能阻止点击功能工作?
- spring - Spring dataRest插入如何仅传递id关系而不是实体
- r - R 中的 H2O 深度学习模型能否在保持多线程的同时可重现?
- cocoapods - 支持模拟器与 iOS 设备的不同供应商框架
- python - 如何确定最佳层数和激活函数
- javascript - 将值附加到 URL 搜索参数
- reactjs - 反应。如何在按钮和页面点击上隐藏结果
- python - 将 >2GB 数据传递给 tf.estimator
- python - 将 idxmin(axis=1) 与数据框一起使用时出现 TypeError