Skip to content

Latest commit

 

History

History
81 lines (60 loc) · 2.69 KB

File metadata and controls

81 lines (60 loc) · 2.69 KB
title Azure IoT Hub libraries for Java
description Reference documentation for the Java Azure IoT Hub libraries
keywords Azure, Java, SDK, API, event, IoT, streams, devices, iot hub
author rloutlaw
ms.author routlaw
manager douge
ms.date 07/20/2017
ms.topic article
ms.technology azure
ms.devlang java
ms.service iot-hub

Azure IoT libraries for Java

Connect, monitor, and control Internet of Things assets with Azure IoT Hub.

To get started with Azure IoT Hub, see Connect your device to your IoT hub using Java.

IoT Service library

Register devices and send messages from the cloud to registered devices using the IoT Service library.

Add a dependency to your Maven pom.xml file to use the client library in your project.

<dependency>
    <groupId>com.microsoft.azure.sdk.iot</groupId>
    <artifactId>iot-service-client</artifactId>
    <version>1.6.23</version>
</dependency>

Iot Device library

Send messages to the cloud and receive messages on devices using the IoT Device library.

Add a dependency to your Maven pom.xml file to use the client library in your project.

<dependency>
    <groupId>com.microsoft.azure.sdk.iot</groupId>
    <artifactId>iot-device-client</artifactId>
    <version>1.3.31</version>
</dependency>

[!div class="nextstepaction"] Explore the Client APIs

Example

Send a message from Azure IoT Hub to a device.

Message messageToSend = new Message(messageText);
messageToSend.setDeliveryAcknowledgement(DeliveryAcknowledgement.Full);
messageToSend.setMessageId(java.util.UUID.randomUUID().toString());

// set message properties
Map<String, String> propertiesToSend = new HashMap<String, String>();
propertiesToSend.put(messagePropertyKey,messagePropertyKey);
messageToSend.setProperties(propertiesToSend);

CompletableFuture<Void> future = serviceClient.sendAsync(deviceId, messageToSend);
try {
    future.get();
}
catch (ExecutionException e) {
    System.out.println("Exception : " + e.getMessage());
}

Samples

IoT Device samples
IoT Service samples

Explore more sample Java code for Azure IoT you can use in your apps.