Class ConnectorWorker
- Namespace
- Azure.Iot.Operations.Connector
- Assembly
- Azure.Iot.Operations.Connector.dll
Base class for a connector worker that allows users to forward data sampled from datasets and/or data received from events.
public class ConnectorWorker : ConnectorBackgroundService, IHostedService, IDisposable
- Inheritance
-
ConnectorWorker
- Implements
- Derived
- Inherited Members
Constructors
ConnectorWorker(ApplicationContext, ILogger<ConnectorWorker>, IMqttClient, IMessageSchemaProvider, IAzureDeviceRegistryClientWrapperProvider, IConnectorLeaderElectionConfigurationProvider?)
public ConnectorWorker(ApplicationContext applicationContext, ILogger<ConnectorWorker> logger, IMqttClient mqttClient, IMessageSchemaProvider messageSchemaProviderFactory, IAzureDeviceRegistryClientWrapperProvider adrClientWrapperFactory, IConnectorLeaderElectionConfigurationProvider? leaderElectionConfigurationProvider = null)
Parameters
applicationContextApplicationContextloggerILogger<ConnectorWorker>mqttClientIMqttClientmessageSchemaProviderFactoryIMessageSchemaProvideradrClientWrapperFactoryIAzureDeviceRegistryClientWrapperProviderleaderElectionConfigurationProviderIConnectorLeaderElectionConfigurationProvider
Fields
WhileAssetIsAvailable
The function to run while an asset is available.
public Func<AssetAvailableEventArgs, CancellationToken, Task>? WhileAssetIsAvailable
Field Value
Remarks
The provided cancellation is signaled when the asset is no longer available or when this connector is no longer the leader (and no longer responsible for interacting with the asset).
Best Practice: Check both Enabled and Enabled properties in your handler. A disabled device or asset should not be processed. Resources can be disabled at discovery time or while the connector is working.
WhileDeviceIsAvailable
Event handler for when an device becomes available.
public Func<DeviceAvailableEventArgs, CancellationToken, Task>? WhileDeviceIsAvailable
Field Value
Remarks
The provided cancellation is signaled when the device is no longer available or when this connector is no longer the leader (and no longer responsible for interacting with the device).
Best Practice: Check the Enabled property in your handler. A disabled device should not be processed. Devices can be disabled at discovery time or while the connector is working.
_adrClient
protected IAzureDeviceRegistryClientWrapper? _adrClient
Field Value
_logger
protected readonly ILogger<ConnectorWorker> _logger
Field Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public override void Dispose()
ExecuteAsync(CancellationToken)
This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.
protected override Task ExecuteAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationToken
Returns
Remarks
See Worker Services in .NET for implementation guidelines.
GetRegisteredDatasetMessageSchema(string, string, string, string)
public MessageSchemaReference? GetRegisteredDatasetMessageSchema(string deviceName, string inboundEndpointName, string assetName, string datasetName)
Parameters
Returns
GetRegisteredEventMessageSchema(string, string, string, string, string)
public MessageSchemaReference? GetRegisteredEventMessageSchema(string deviceName, string inboundEndpointName, string assetName, string eventGroupName, string eventName)
Parameters
deviceNamestringinboundEndpointNamestringassetNamestringeventGroupNamestringeventNamestring
Returns
RunConnectorAsync(CancellationToken)
Run the connector worker.
public override Task RunConnectorAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
This will run the connector until the provided cancellation token is cancelled.