public class AzureIoTExample {
private static AzureIoTExample.MessageCallbackMqtt msgCallback = new AzureIoTExample.MessageCallbackMqtt();
protected static class MessageCallbackMqtt implements MessageCallback {
@Override
public IotHubMessageResult execute(Message msg, Object context) {
return IotHubMessageResult.COMPLETE;
}
}
private static ModuleClient client = null;
public static void main(String[] args) throws IOException, ModuleClientException {
IotHubClientProtocol protocol = IotHubClientProtocol.MQTT;
client = ModuleClient.createFromEnvironment (protocol);
client.setMessageCallback("Input", msgCallback, client);
client.registerConnectionStatusChangeCallback(new ConnectionStatusChangeCallback(), null);
client.open();
System.out.print(System.getenv("IothubConnectionstringVariableName"));
}
}
Trying to connect with IoTEdge using Azure Java SDK via ModuleClient Class of azure.sdk.iot.device Package. when I'm running the code. was getting an error i.e., Environment IoTEdge_WorkLoadURI is required.
To Achieve the connection what exactly needs to done and How to Achieve this ??
String connString = System.getenv("IOTEDGECONNECTIONSTRING");
pom.xml:
Output: