Table of Contents

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

applicationContext ApplicationContext
logger ILogger<ConnectorWorker>
mqttClient IMqttClient
messageSchemaProviderFactory IMessageSchemaProvider
adrClientWrapperFactory IAzureDeviceRegistryClientWrapperProvider
leaderElectionConfigurationProvider IConnectorLeaderElectionConfigurationProvider

Fields

WhileAssetIsAvailable

The function to run while an asset is available.

public Func<AssetAvailableEventArgs, CancellationToken, Task>? WhileAssetIsAvailable

Field Value

Func<AssetAvailableEventArgs, CancellationToken, Task>

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

Func<DeviceAvailableEventArgs, CancellationToken, Task>

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

IAzureDeviceRegistryClientWrapper

_logger

protected readonly ILogger<ConnectorWorker> _logger

Field Value

ILogger<ConnectorWorker>

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

cancellationToken CancellationToken

Returns

Task

A Task that represents the long running operations.

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

deviceName string
inboundEndpointName string
assetName string
datasetName string

Returns

MessageSchemaReference

GetRegisteredEventMessageSchema(string, string, string, string, string)

public MessageSchemaReference? GetRegisteredEventMessageSchema(string deviceName, string inboundEndpointName, string assetName, string eventGroupName, string eventName)

Parameters

deviceName string
inboundEndpointName string
assetName string
eventGroupName string
eventName string

Returns

MessageSchemaReference

RunConnectorAsync(CancellationToken)

Run the connector worker.

public override Task RunConnectorAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Cancellation token.

Returns

Task

Remarks

This will run the connector until the provided cancellation token is cancelled.