本文整理汇总了Java中com.amazonaws.services.iot.client.AWSIotMqttClient.attach方法的典型用法代码示例。如果您正苦于以下问题:Java AWSIotMqttClient.attach方法的具体用法?Java AWSIotMqttClient.attach怎么用?Java AWSIotMqttClient.attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.iot.client.AWSIotMqttClient
的用法示例。
在下文中一共展示了AWSIotMqttClient.attach方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectToAwsEventHub
import com.amazonaws.services.iot.client.AWSIotMqttClient; //导入方法依赖的package包/类
private void connectToAwsEventHub() throws AWSIotException
{
applyProperties();
if (propertiesNeedUpdating)
{
cleanup();
propertiesNeedUpdating = false;
}
// iot service type - IOT_TOPIC | IOT_DEVICE
isEventHubType = AwsIoTServiceType.IOT_TOPIC.toString().equals(iotServiceType);
// get KeyStore credentials
KeyStorePasswordPair pair = AwsIoTHubUtil.getKeyStorePasswordPair(x509Certificate, privateKey, null);
// create AwsClient
clientId = String.format("%s-%s", thingName, new BigInteger(128, new SecureRandom()).toString(32));
awsClient = new AWSIotMqttClient(clientEndpoint, clientId, pair.keyStore, pair.keyPassword);
// attach device
if (!isEventHubType)
{
// IoT Device attach
geIoTDevice = new AwsIoTHubDevice(thingName);
LOGGER.info(System.currentTimeMillis() + ": ClientId: " + clientId + ": Attaching device:" + geIoTDevice.getThingName());
awsClient.attach(geIoTDevice);
}
// connect to Aws IoT Hub
LOGGER.info(System.currentTimeMillis() + ": ClientId: " + clientId + ": Connecting");
awsClient.connect();
LOGGER.info(System.currentTimeMillis() + ": ClientId: " + clientId + ": Connected");
// geIoTDevice.delete(10000); // delete shadow
}
示例2: connectToAwsEventHub
import com.amazonaws.services.iot.client.AWSIotMqttClient; //导入方法依赖的package包/类
private void connectToAwsEventHub()
{
String errorMessage = null;
RunningState runningState = RunningState.STARTED;
try
{
applyProperties();
if (propertiesNeedUpdating)
{
cleanup();
propertiesNeedUpdating = false;
}
// iot service type: IOT_TOPIC|IOT_DEVICE
isEventHubType = AwsIoTServiceType.IOT_TOPIC.toString().equals(iotServiceType);
// Get KeyStore credentials
KeyStorePasswordPair pair = AwsIoTHubUtil.getKeyStorePasswordPair(x509Certificate, privateKey, null);
// create AwsClient
clientId = String.format("%s-%s", thingName, new BigInteger(128, new SecureRandom()).toString(32));
awsClient = new AWSIotMqttClient(clientEndpoint, clientId, pair.keyStore, pair.keyPassword);
if (awsClient == null)
{
runningState = RunningState.ERROR;
errorMessage = LOGGER.translate("FAILED_TO_CREATE_EH_CLIENT", clientEndpoint);
LOGGER.error(errorMessage);
}
// attach device
if (!isEventHubType)
{
LOGGER.info(System.currentTimeMillis() + ": ClientId: " + ": Attaching device:" + geIoTDevice.getThingName());
geIoTDevice = new AwsIoTHubDevice(thingName);
awsClient.attach(geIoTDevice);
}
// connect
LOGGER.info(System.currentTimeMillis() + ": ClientId: " + clientId + ": Connecting");
awsClient.connect();
LOGGER.info(System.currentTimeMillis() + ": ClientId: " + clientId + ": Connected");
// geIoTDevice.delete(10000); // delete shadow
// register topic handler
iotTopic = new AwsIoTTopicListener(topicName, AWSIotQos.QOS0);
awsClient.subscribe(iotTopic, true);
LOGGER.info("Subscribed to topic:" + topicName);
setErrorMessage(errorMessage);
setRunningState(runningState);
}
catch (AWSIotException iote)
{
LOGGER.error("AWSIOT_INIT_ERROR", iote);
setErrorMessage(iote.getMessage());
setRunningState(RunningState.ERROR);
}
catch (Exception ex)
{
LOGGER.error("INIT_ERROR", ex);
setErrorMessage(ex.getMessage());
setRunningState(RunningState.ERROR);
}
}