当前位置: 首页>>代码示例>>Java>>正文


Java AWSIotMqttClient类代码示例

本文整理汇总了Java中com.amazonaws.services.iot.client.AWSIotMqttClient的典型用法代码示例。如果您正苦于以下问题:Java AWSIotMqttClient类的具体用法?Java AWSIotMqttClient怎么用?Java AWSIotMqttClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AWSIotMqttClient类属于com.amazonaws.services.iot.client包,在下文中一共展示了AWSIotMqttClient类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: AwsIot

import com.amazonaws.services.iot.client.AWSIotMqttClient; //导入依赖的package包/类
public AwsIot(Node root, String region, String accessKeyId, String secretAccessKey, KeyStore keyStore,
        String keyPassword) {
    AWSCredentials awsCredentials = new BasicAWSCredentials(accessKeyId, secretAccessKey);

    this.client = new AWSIotClient(awsCredentials);
    this.client.withRegion(Regions.fromName(region));

    String endpoint = getEndpoint();
    String clientId = UUID.randomUUID().toString();
    if (keyStore != null && keyPassword != null) {
        this.mqttClient = new AWSIotMqttClient(endpoint, clientId, keyStore, keyPassword);
    } else {
        this.mqttClient = new AWSIotMqttClient(endpoint, clientId, accessKeyId, secretAccessKey);
    }

    try {
        this.mqttClient.connect();
    } catch (AWSIotException e) {
        throw new RuntimeException("Failed to connect to AWS IoT service", e);
    }

    this.root = root;
}
 
开发者ID:awslabs,项目名称:aws-iot-fuse,代码行数:24,代码来源:AwsIot.java

示例2: setClient

import com.amazonaws.services.iot.client.AWSIotMqttClient; //导入依赖的package包/类
public static void setClient(AWSIotMqttClient client) {
    awsIotClient = client;
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:4,代码来源:PublishSubscribeSample.java

示例3: 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
}
 
开发者ID:Esri,项目名称:aws-for-geoevent,代码行数:36,代码来源:AwsIoTHubOutboundTransport.java

示例4: 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);
  }
}
 
开发者ID:Esri,项目名称:aws-for-geoevent,代码行数:67,代码来源:AwsIoTHubInboundTransport.java

示例5: BlockingPublisher

import com.amazonaws.services.iot.client.AWSIotMqttClient; //导入依赖的package包/类
public BlockingPublisher(AWSIotMqttClient awsIotClient) {
    this.awsIotClient = awsIotClient;
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:4,代码来源:PublishSubscribeSample.java

示例6: NonBlockingPublisher

import com.amazonaws.services.iot.client.AWSIotMqttClient; //导入依赖的package包/类
public NonBlockingPublisher(AWSIotMqttClient awsIotClient) {
    this.awsIotClient = awsIotClient;
}
 
开发者ID:aws,项目名称:aws-iot-device-sdk-java,代码行数:4,代码来源:PublishSubscribeSample.java


注:本文中的com.amazonaws.services.iot.client.AWSIotMqttClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。