use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinClientOptions in project azure-iot-sdk-java by Azure.
the class RoleBasedAuthenticationSample method runTwinClientSample.
private static void runTwinClientSample(String iotHubHostName, TokenCredential credential, String deviceId) {
// DeviceTwin has some configurable options for HTTP read and connect timeouts, as well as for setting proxies.
// For this sample, the default options will be used though.
DeviceTwinClientOptions options = DeviceTwinClientOptions.builder().build();
// This constructor takes in your implementation of TokenCredential which allows you to use RBAC authentication
// rather than symmetric key based authentication that comes with constructors that take connection strings.
DeviceTwin twinClient = new DeviceTwin(iotHubHostName, credential, options);
DeviceTwinDevice newDeviceTwin = new DeviceTwinDevice(deviceId);
try {
System.out.println("Getting twin for device " + deviceId);
twinClient.getTwin(newDeviceTwin);
} catch (IotHubException | IOException e) {
System.err.println("Failed to get twin for device " + deviceId);
e.printStackTrace();
System.exit(-1);
}
System.out.println("Successfully got the twin for the new device");
System.out.println("Device Id: " + newDeviceTwin.getDeviceId());
System.out.println("ETag: " + newDeviceTwin.getETag());
}
Aggregations