This repository is an example of how to build and run a Docker image that contains a Java based Azure IoT device client.
You can execute the Java based IoT device client using a Docker image or in standalone Java application mode.
The IoT device client sample in this repository is based on the Azure IoT SDK and sample apps . Please visit the link above to become familiar with the capabilities of the Azure IoT device Java SDK.
This implementation extends the Azure samples with the following features: * Send messages using a configurable interval. * Simulate multiple devices each of which can send messages at configured inteval. * Multi-device simulation for AMQPS is currently not supported. * Sends an eventcontaining temperature, humidity and device timestamp in JSON format. * Self-registration of IoT Devices using the RegistryManager API, no pre-registration required. * Clean-up and delete auto-registered IoT devices after each run using
The event is sent using the following JSON format:
{"deviceId":"io.github.stansa.azureiotsample:f6b51682-5c54-4186-af47-b43277c81b74","timestamp":"2016-02-29T19:57:11.780Z","temperature":7.0,"humidity":55.0}
Minimal Docker image to run Java applications. This is based on Alpine Linux to keep the size minimal (about 25% of an ubuntu-based image).
https://hub.docker.com/r/stans/azureiotclient/
latest
: Run a device simulationcleanup
: Cleanup devices from Registry
Example of running a simulation for a single IoT device client:
docker run -e "PROTOCOL=amqps" -e "HUB_CONN_STRING=HostName=company1.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=Abcdefghijklmnopqrstuvwxyz=” stans/azureiotclient
Example of cleanup and deletion of IoT device client created during the simulation:
docker run -e "HUB_CONN_STRING=HostName=company1.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=Abcdefghijklmnopqrstuvwxyz=” stans/azureiotclient:cleanup
-
Run using Azure Container Service https://azure.microsoft.com/en-us/documentation/articles/container-service-intro/
-
Run using Docker Cloud and Microsoft Azure integration https://docs.docker.com/docker-cloud/getting-started/link-azure/
-
Roll your own orchestration using Azure VMs and/or Docker Swarm: https://docs.docker.com/swarm/overview/
-
Run on any other Docker compliant container service such as AWS Container Service
-
create a jar -
./mvn clean package
-
go to
target/
to find the azureiot-1.0-SNAPSHOT-with-deps.jar -
execute
java -jar
java -jar -Dazureiot_num_devices= -Dazureiot_device_data_interval= -Dazureiot_conn_string= -Dazureiot_protocol="https|mqtt_amqps" azureiot-1.0-SNAPSHOT-with-deps.jar
java -jar -Dazureiot_num_devices=3 -Dazureiot_device_data_interval=15 -Dazureiot_conn_string=HostName=company1.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=Abcdefghijklmnopqrstuvwxyz=" -Dazureiot_protocol="mqtt" azureiot-1.0-SNAPSHOT-with-deps.jar
java -jar -Dazureiot_conn_string=HostName=company1.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=Abcdefghijklmnopqrstuvwxyz=" azureiot-1.0-SNAPSHOT-with-deps.jar io.github.stansa.azureiotsample.CleanUpRegistry