ThingWorx Azure IoT Hub Connector for Microsoft Azure Industrial IoT (IIoT) for OPC UA > Deploying Multiple Connectors for the OPC UA Integration
Deploying Multiple Connectors for the OPC UA Integration
Each ThingWorx Azure IoT Hub Connector communicates with only one Azure IoT Hub. However, a single Azure IoT Hub can communicate with multiple Azure IoT Hub Connectors. This multi-Connector deployment provides failover and load balancing automatically. Consider the following components:
Managing the IoT Edge Runtime/Microsoft Industrial IoT Platform — One Connector is the leader in a group of Connectors, and that Connector is the only one that can query and manage OPC UA subscriptions in the ThingWorx Kepware Server (TKS) or other OPC UA Server.
Telemetry — IoT Edge Runtime devices have identifiers, called Device ids, that are associated with them in the Azure IoT Hub. The IoT Hub uses these identifiers to map telemetry from the Edge to its partitions. If these identifiers are different enough, the data sent to the Hub via two Edge Runtime devices could land on two different partitions. In this case, adding a second IoT Hub Connector will distribute the load automatically. There is no additional configuration needed in the deployment to make this happen. To take advantage of automatic load balancing, you need to deploy more than one IoT Edge Runtime device.
If you are using the Azure IIoT OPC UA integration, all data from a single Publisher module goes through the same partition on the Hub
The logic that maps a Device id to a partition is proprietary to Microsoft Azure. For this reason, it is not possible to predict which partition a Publisher will be mapped to.
An Azure IoT Hub is represented in ThingWorx by an AzureIotHubTemplate Thing. When it starts up, a Connector uses the name of the AzureIotHubTemplate Thing to load its configuration. The configuration of the AzureIotHubTemplate Thing in ThingWorx includes properties that enable the Connector and Azure IoT Hub to communicate securely. One of the properties is the consumer group name. This property is important when you want to deploy multiple Connectors that communicate with the same Azure IoT Hub.
When deploying multiple Connectors, only one Connector will be the leader and there will be only one consumer group across all the Connectors. Adding another consumer group to your IoT Hub would cause duplicate telemetry in ThingWorx because each Connector will process all of the data coming through.
The load balancing and failover when you deploy multiple Connectors with the same Azure IoT Hub happens automatically. The ThingWorx Platform decides which Connector is the leader, and maintains the leader as necessary when Connectors fail or are restarted.
To ensure automatic load balancing and failover, all of the Connectors must be configured with the same consumer group. For information about configuring the consumer group in Azure IoT, refer to the best practice note in Step 3 of the topic, Step 1. Create and Configure Items in Azure IoT.
You can have more than two Connectors that share an Azure IoT Hub. However, the current implementation of the ThingWorx Azure IoT Extension does not support multiple IoT Hubs talking to one ThingWorx Platform.
Example of Deploying Multiple Connectors
Consider the following scenario:
Two factories, each with one ThingWorx Kepware Server (TKS) and one Azure IoT Edge Runtime installation. The Azure IIoT OPC UA integration will have two TKS and two IoT Edge Runtime instances.
One Azure IoT Hub in Azure IoT.
One ThingWorx Platform instance and two ThingWorx Azure IoT Hub Connectors.
What needs to be configured for this scenario follows:
1. In Azure IoT, configure the Azure IoT Hub with one consumer group that is not the $Default consumer group.
2. In ThingWorx Composer, configure the AzureIotHubTemplate Thing with that consumer group. In the configuration file for each Connector, specify the name of the configured AzureIotHubTemplate Thing. When they start up the Connectors will get the consumer group from the configuration of the AzureIotHubTemplate Thing.
3. The two Connectors connect to the same Azure IoT Hub, so ThingWorx Platform automatically selects one as the leader. The other is the follower. Regardless of their status as leader or follower, when these Connectors receive telemetry, they will route the telemetry to the ThingWorx Platform.
In this deployment scenario, telemetry routing is expected to work normally.