Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Get started developing with the Azure IoT Operations SDKs. Follow these steps to set up your development environment for building and running the samples, as well as creating and testing your own highly available edge applications.
GitHub repository | .NET SDK | Go SDK | Rust SDK
Prerequisites
Before you begin, prepare the following prerequisites:
An Azure subscription. If you don't have an Azure subscription, create one for free.
A GitHub account.
Azure access permissions. For more information, see Deployment details > Required permissions.
Setting up
Developing with the Azure IoT Operations SDKs requires a Kubernetes cluster with Azure IoT Operations deployed. Further configuration allows you to access the MQTT broker directly from the developer environment.
Important
The following development environment setup options use K3s running in K3d for a lightweight Kubernetes cluster. They deploy Azure IoT Operations with test settings. For production deployments, choose secure settings.
To use secure settings, follow the instructions in Prepare your Azure Arc-enabled Kubernetes cluster to create a K3s cluster on Ubuntu and Deploy Azure IoT Operations to a production cluster to deploy with secure settings. Then proceed to configure Azure IoT Operations for development.
GitHub Codespaces provides the most streamlined experience and can get the development environment up and running in a couple of minutes.
Deploy Azure IoT Operations
You'll arc-enable the development cluster created in the previous step and deploy Azure IoT Operations with test settings.
Open a new Bash terminal and complete the following steps:
Go to the repository root directory:
cd <REPOSITORY ROOT>Run the
install-aio-arc.shscript to arc-enable your cluster and deploy Azure IoT Operations. Replace the placeholders with your values:Parameter Value LOCATIONAn Azure region close to you. For the list of currently supported regions, see Supported regions. RESOURCE_GROUPA name for a new Azure resource group where your cluster will be created. CLUSTER_NAMEA name for your Kubernetes cluster. STORAGE_ACCOUNT_NAMEA name for your storage account. Storage account names must be between 3 and 24 characters in length and only contain numbers and lowercase letters. SCHEMA_REGISTRY_NAMEA name for your schema registry. Schema registry names can only contain numbers, lowercase letters, and hyphens. SCHEMA_REGISTRY_NAMESPACEA name for your schema registry namespace. The namespace uniquely identifies a schema registry within a tenant. Schema registry namespace names can only contain numbers, lowercase letters, and hyphens. ./tools/deployment/install-aio-arc.sh -l <LOCATION> -g <RESOURCE_GROUP> -c <CLUSTER_NAME> -s <STORAGE_ACCOUNT_NAME> -r <SCHEMA_REGISTRY_NAME> -n <SCHEMA_REGISTRY_NAMESPACE>This script runs the following commands:
- Log in to Azure CLI
- Create a resource group
- Register required Azure providers
- Connect Kubernetes cluster to Azure Arc
- Enable Azure Arc features
- Create Azure Storage account
- Create Azure IoT Operations schema registry
- Initialize Azure IoT Operations
- Create Azure IoT Operations instance
After the deployment finishes, use az iot ops check to evaluate Azure IoT Operations service deployment for health, configuration, and usability. The check command can help you find problems in your deployment and configuration.
az iot ops check
Configure Azure IoT Operations for development
After you deploy Azure IoT Operations, configure it for development. Set up the MQTT broker and authentication methods. Make sure you set the necessary environment variables for your development environment:
Go to the repository root directory:
cd <REPOSITORY ROOT>Run the
configure-aio.shscript to configure Azure IoT Operations for development:./tools/deployment/configure-aio.shThis script runs the following commands:
- Sets up certificate services, if missing
- Creates root and intermediate CAs for x509 authentication
- Creates the trust bundle ConfigMap for the Broker to authentication x509 clients
- Configures
BrokerListenerandBrokerAuthenticationresources for SAT and x509 auth
Testing the installation
To test the setup, use mosquitto_pub to connect to the MQTT broker and validate the x509 certs, SAT, and trust bundle.
Export the
.sessiondirectory:export SESSION=$(git rev-parse --show-toplevel)/.sessionTest no TLS, no auth:
mosquitto_pub -L mqtt://localhost:1883/hello -m world --debugTest TLS with x509 auth:
mosquitto_pub -L mqtts://localhost:8883/hello -m world --cafile $SESSION/broker-ca.crt --cert $SESSION/client.crt --key $SESSION/client.key --debugTest TLS with SAT auth:
mosquitto_pub -L mqtts://localhost:8884/hello -m world --cafile $SESSION/broker-ca.crt -D CONNECT authentication-method K8S-SAT -D CONNECT authentication-data $(cat $SESSION/token.txt) --debug
Run a sample
This sample demonstrates a simple communication between a client and a server using Telemetry and remote procedure call (RPC). The server tracks the value of a counter and accepts RPC requests from the client to either read or increment that counter.
The sample uses the v2 protocol compiler with WoT Thing model files, see the TestThing folder.
Install the .NET 9.0 SDK.
The samples within Azure IoT Operations SDKs GitHub repository read configuration from environment variables. The repository root provides an
.envfile that exports the variables used by the samples to connect to the MQTT broker. Edit the.envfile to set the values for your environment, or use the default values provided in the file.Navigate to the
CounterServersample directory:cd <REPOSITORY ROOT>/dotnet/samples/Protocol/RPC/CounterServer/Build the sample:
dotnet buildRun the sample:
source `git rev-parse --show-toplevel`/.env; export AIO_MQTT_CLIENT_ID=counter-server; dotnet runOpen a new shell and navigate to the
CounterClientsample directory:cd <REPOSITORY ROOT>/dotnet/samples/Protocol/RPC/CounterClient/Build the sample:
dotnet buildRun the sample:
source `git rev-parse --show-toplevel`/.env; export AIO_MQTT_CLIENT_ID=counter-client; export COUNTER_SERVER_ID=counter-server; dotnet runYou see the client and server communicating, with the client sending requests to read and increment the counter value. This example shows the output messages that you can see:
CounterClient output:
CounterClient Information: 0 : Invoked command 'readCounter' with correlation ID 12345 to topic 'rpc/command-samples/counter-server/readCounter' CounterClient Information: 0 : Invoked command 'increment' with correlation ID 123456 to topic 'rpc/command-samples/counter-server/increment' info: CounterClient.RpcCommandRunner[0] called counter.incr 1 with id 12346 info: CounterClient.CounterClient[0] Telemetry received from counter-server: CounterValue=1 info: CounterClient.RpcCommandRunner[0] counter 32 with id 12345 info: CounterClient.RpcCommandRunner[0] Current telemetry count: 32CounterServer output:
CounterServer Information: 0 : Command executor for 'reset' started. CounterServer Information: 0 : Command executor for 'increment' started. CounterServer Information: 0 : Command executor for 'readCounter' started. CounterServer.CounterService[0] --> Executing Counter.ReadCounter with id 12345 for counter-client CounterServer.CounterService[0] --> Executed Counter.ReadCounter with id 12345 for counter-client CounterServer.CounterService[0] --> Executing Counter.Increment with id 12346 for counter-client CounterServer.CounterService[0] --> Executed Counter.Increment with id 12346 for counter-client CounterServer Information: 0 : Telemetry sent successfully to the topic 'telemetry/telemetry-samples/counterValue'The
CounterClientsample automatically exits when it completes. You can also stop theCounterServersample by pressingCtrl+Cin its terminal.
Configuration summary
MQTT broker configuration
After you install the software, the cluster contains the following MQTT broker definitions:
| Component Type | Name | Description |
|---|---|---|
Broker |
default | The MQTT broker |
BrokerListener |
default | Provides cluster access to the MQTT broker |
BrokerListener |
default-external | Provides off-cluster access to the MQTT broker |
BrokerAuthentication |
default | SAT authentication definition |
BrokerAuthentication |
default-x509 | An x509 authentication definition |
MQTT broker access
You can access the MQTT broker both on-cluster and off-cluster by using the connection information described in the following table. For information on which environment variables to use when configuring your application, see Connection Settings.
Note
The hostname when accessing the MQTT broker off-cluster might differ from localhost depending on your setup.
| Hostname | Authentication | TLS | On cluster port | Off cluster port |
|---|---|---|---|---|
aio-broker |
SAT | ✅ | 18883 |
- |
localhost |
None | ❌ | 1883 |
1883 |
localhost |
x509 | ✅ | 8883 |
8883 |
localhost |
SAT | ✅ | 8884 |
8884 |
Development artifacts
As part of the deployment script, the local environment creates the following files to facilitate connection and authentication to the MQTT broker. You can find these files in the .session directory at the repository root.
| File | Description |
|---|---|
broker-ca.crt |
The MQTT broker trust bundle required to validate the MQTT broker on ports 8883 and 8884 |
token.txt |
A service authentication token (SAT) for authenticating with the MQTT broker on 8884 |
client.crt |
An x509 client certificate for authenticating with the MQTT broker on port 8883 |
client.key |
An x509 client private key for authenticating with the MQTT broker on port 8883 |
Troubleshooting
Check the troubleshooting guide for common issues in the Azure IoT Operations SDKs GitHub repository.
Next steps
In this quickstart, you set up the Azure IoT Operations SDKs and ran a sample application. To learn more about developing with the SDKs, check out the following resources: