protocol.name()); DeviceClient client = new DeviceClient(connString, protocol); client.closeNow(); scanner.nextLine(); System.out.println("Shutting down..."); client.closeNow();
/** * @param props * @throws URISyntaxException * @throws IOException */ public AzureIoTHubLogger(final Map<String, Object> props) throws URISyntaxException, IOException { super(); this.deviceClient = new DeviceClient((String)props.get("connectionString"), IotHubClientProtocol.valueOf((String)props.get("protocol"))); this.deviceClient.open(); }
@Override public void logEvent(String event, Map<String, Object> producerConfig) { this.deviceClient.sendEventAsync(new Message(event), null, null); }
private void createDevice(IotHubClientProtocol protocol) throws IOException, URISyntaxException, InterruptedException { testDevice.deviceClient = new DeviceClient(DeviceConnectionString.get(iotHubConnectionString, deviceForRegistryManager), protocol); IotHubServicesCommon.openClientWithRetry(testDevice.deviceClient); testDevice.deviceClient.startDeviceTwin(new DeviceTwinStatusCallBack(), testDevice, new DeviceTwinPropertyCallback(), testDevice); }
System.out.format("Using communication protocol %s.\n", protocol.name()); DeviceClient client = new DeviceClient(connString, protocol); client.setMessageCallback(callback, counter); client.setMessageCallback(callback, counter); client.registerConnectionStatusChangeCallback(new IotHubConnectionStatusChangeCallbackLogger(), new Object()); client.open(); scanner.nextLine(); client.closeNow();
DeviceClient client = new DeviceClient(arguments.connectionString, arguments.protocol); client.open(); client.sendEventAsync(msg, callback, lockobj); client.closeNow(); } catch (Exception e) { System.out.println("Failure: " + e.toString());
try deviceClient = DeviceClient.createFromSecurityProvider(iotHubUri, deviceId, securityProviderX509, IotHubClientProtocol.MQTT); deviceClient.open(); Message messageToSendFromDeviceToHub = new Message("Whatever message you would like to send"); deviceClient.sendEventAsync(messageToSendFromDeviceToHub, new IotHubEventCallbackImpl(), null); if (deviceClient != null) deviceClient.closeNow(); deviceClient.closeNow();
protocol.name()); DeviceClient client = new DeviceClient(connString, protocol); System.out.println("Successfully created an IoT Hub client."); client.registerConnectionStatusChangeCallback(new IotHubConnectionStatusChangeCallbackLogger(), new Object()); client.open(); client.startDeviceTwin(new DeviceTwinStatusCallBack(), null, new onProperty(), null); do client.subscribeToTwinDesiredProperties(desiredProperties); client.getDeviceTwin(); // For each desired property in the Service, the SDK will call the appropriate callback with the value and version. client.sendReportedProperties(reportProperties); client.sendReportedProperties(new HashSet<Property>() {{ add(new Property("HomeSecurityCamera", CAMERA.DETECTED_BURGLAR)); }}); client.sendReportedProperties(new HashSet<Property>() {{ add(new Property("HomeSecurityCamera", CAMERA.SAFELY_WORKING)); }}); client.sendReportedProperties(new HashSet<Property>() {{ add(new Property("BedroomRoomLights", null)); }}); client.closeNow(); System.out.println("Shutting down..."); client.closeNow();
protocol.name()); DeviceClient client = new DeviceClient(connString, protocol); client.registerConnectionStatusChangeCallback(new IotHubConnectionStatusChangeCallbackLogger(), new Object()); client.open(); client.subscribeToDeviceMethod(new SampleDeviceMethodCallback(), null, new DeviceMethodStatusCallBack(), null); client.closeNow(); System.out.println("Shutting down..."); client.closeNow(); System.out.println("Shutting down...");
/** * Creates a device client that uses the provided security provider for authentication. * * @param uri The connection string for iot hub to connect to (format: "yourHubName.azure-devices.net") * @param deviceId The id for the device to use * @param securityProvider The security provider for the device * @param protocol The protocol the device shall use for communication to the IoT Hub * @return The created device client instance * @throws URISyntaxException If the provided connString could not be parsed. * @throws IOException If the SecurityProvider throws any exception while authenticating */ public static DeviceClient createFromSecurityProvider(String uri, String deviceId, SecurityProvider securityProvider, IotHubClientProtocol protocol) throws URISyntaxException, IOException { return new DeviceClient(uri, deviceId, securityProvider, protocol); }
DeviceClient client1 = new DeviceClient(connString1, transportClient); if (pathToCertificate1 != null) client1.setOption("SetCertificatePath", pathToCertificate1); client1.setOption("SetSASTokenExpiryTime", time1); client1.setMessageCallback(callback1, counter1); DeviceClient client2 = new DeviceClient(connString2, transportClient); if (pathToCertificate2 != null) client2.setOption("SetCertificatePath", pathToCertificate2); client2.setOption("SetSASTokenExpiryTime", time2); client2.setMessageCallback(callback2, counter2); DeviceClient client3 = new DeviceClient(connString3, transportClient); if (pathToCertificate3 != null) client3.setOption("SetCertificatePath", pathToCertificate3); client3.setOption("SetSASTokenExpiryTime", time3); client3.setMessageCallback(callback3, counter3); client1.subscribeToDeviceMethod(new SampleDeviceMethodCallback(), null, new DeviceMethodStatusCallBack1(), null); client2.subscribeToDeviceMethod(new SampleDeviceMethodCallback(), null, new DeviceMethodStatusCallBack2(), null);
protocol.name()); DeviceClient client = new DeviceClient(connString, protocol); client.uploadToBlobAsync(file.getName(), new FileInputStream(file), file.length(), new FileUploadStatusCallBack(), null); client.closeNow(); scanner.nextLine(); System.out.println("Shutting down..."); client.closeNow();
@Test public void invokeMethodAMQPSSucceed() throws Exception { TransportClient transportClient = new TransportClient(AMQPS); ArrayList<InternalClient> clientArrayList = new ArrayList<>(); for (int i = 0; i < MAX_DEVICE_MULTIPLEX; i++) { clientArrayList.add(new DeviceClient(clientConnectionStringArrayList[i], transportClient)); } IotHubServicesCommon.openTransportClientWithRetry(transportClient, clientArrayList); for (int i = 0; i < clientArrayList.size(); i++) { ((DeviceClient)clientArrayList.get(i)).subscribeToDeviceMethod(new SampleDeviceMethodCallback(), null, new DeviceMethodStatusCallBack(), null); CountDownLatch countDownLatch = new CountDownLatch(1); RunnableInvoke runnableInvoke = new RunnableInvoke(methodServiceClient, deviceListAmqps[i].getDeviceId(), METHOD_NAME, METHOD_PAYLOAD, countDownLatch); new Thread(runnableInvoke).start(); countDownLatch.await(); MethodResult result = runnableInvoke.getResult(); Assert.assertNotNull(buildExceptionMessage(runnableInvoke.getException() == null ? "Runnable returns null without exception information" : runnableInvoke.getException().getMessage(), clientArrayList.get(i)), result); Assert.assertEquals(buildExceptionMessage("result was not success, but was: " + result.getStatus(), clientArrayList.get(i)), (long)METHOD_SUCCESS,(long)result.getStatus()); Assert.assertEquals(buildExceptionMessage("Received unexpected payload", clientArrayList.get(i)), runnableInvoke.getExpectedPayload(), METHOD_NAME + ":" + result.getPayload().toString()); } transportClient.closeNow(); }
private void tearDownDeviceClient() throws IOException { deviceClient.closeNow(); deviceClient = null; }
@Test public void receiveMessagesOverAmqpsIncludingProperties() throws Exception { TransportClient transportClient = new TransportClient(AMQPS); final ArrayList<InternalClient> clientArrayList = new ArrayList<>(); for (int i = 0; i < MAX_DEVICE_MULTIPLEX; i++) { clientArrayList.add(new DeviceClient(clientConnectionStringArrayList[i], transportClient)); } IotHubServicesCommon.openTransportClientWithRetry(transportClient, clientArrayList); for (int i = 0; i < clientArrayList.size(); i++) { Success messageReceived = new Success(); com.microsoft.azure.sdk.iot.device.MessageCallback callback = new MessageCallback(); ((DeviceClient)clientArrayList.get(i)).setMessageCallback(callback, messageReceived); sendMessageToDevice(deviceListAmqps[i].getDeviceId(), "AMQPS"); waitForMessageToBeReceived(messageReceived, "AMQPS", clientArrayList.get(i)); Thread.sleep(200); } transportClient.closeNow(); }
EventCallback messageCallback = new EventCallback(IotHubStatusCode.UNAUTHORIZED); client.registerConnectionStateCallback(stateCallback, statusUpdated); client.sendEventAsync(messageToSend, messageCallback, messageSent);
((DeviceClient) testInstance.client).setMessageCallback(callBackOnRx, null);
System.out.format("Using communication protocol %s.\n", protocol.name()); DeviceClient client = new DeviceClient(connString, protocol, publicKeyCertificateString, false, privateKeyString, false); client.setMessageCallback(callback, counter); client.registerConnectionStatusChangeCallback(new IotHubConnectionStatusChangeCallbackLogger(), new Object()); client.open(); System.out.println(msgStr); EventCallback eventCallback = new EventCallback(); client.sendEventAsync(msg, eventCallback, msg); client.closeNow();
System.out.format("Using communication protocol %s.\n", protocol.name()); DeviceClient client = new DeviceClient(connectionString, protocol, publicKeyCertificateString, false, privateKeyString, false); client.open(); client.sendEventAsync(msg, callback, msg); client.closeNow();
try deviceClient = DeviceClient.createFromSecurityProvider(iotHubUri, deviceId, securityClientSymmetricKey, IotHubClientProtocol.MQTT); deviceClient.open(); Message messageToSendFromDeviceToHub = new Message("Whatever message you would like to send"); deviceClient.sendEventAsync(messageToSendFromDeviceToHub, new IotHubEventCallbackImpl(), null); if (deviceClient != null) deviceClient.closeNow(); deviceClient.closeNow();