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, IAdrClientWrapperProvider, IConnectorLeaderElectionConfigurationProvider?)
public ConnectorWorker(ApplicationContext applicationContext, ILogger<ConnectorWorker> logger, IMqttClient mqttClient, IMessageSchemaProvider messageSchemaProviderFactory, IAdrClientWrapperProvider adrClientWrapperFactory, IConnectorLeaderElectionConfigurationProvider? leaderElectionConfigurationProvider = null)
Parameters
applicationContext
ApplicationContextlogger
ILogger<ConnectorWorker>mqttClient
IMqttClientmessageSchemaProviderFactory
IMessageSchemaProvideradrClientWrapperFactory
IAdrClientWrapperProviderleaderElectionConfigurationProvider
IConnectorLeaderElectionConfigurationProvider
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).
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).
_adrClient
protected IAdrClientWrapper? _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
cancellationToken
CancellationToken
Returns
Remarks
See Worker Services in .NET for implementation guidelines.
ForwardReceivedEventAsync(string, string, Asset, string, AssetEvent, byte[], Dictionary<string, string>?, CancellationToken)
Push a received event payload to the configured destinations.
public Task ForwardReceivedEventAsync(string deviceName, string inboundEndpointName, Asset asset, string assetName, AssetEvent assetEvent, byte[] serializedPayload, Dictionary<string, string>? userData = null, CancellationToken cancellationToken = default)
Parameters
deviceName
stringThe name of the device that this event belongs to
inboundEndpointName
stringThe name of the inbound endpoint that this event belongs to
asset
AssetThe asset that this event came from.
assetName
stringThe name of the asset that this event belongs to.
assetEvent
AssetEventThe event.
serializedPayload
byte[]The payload to push to the configured destinations.
userData
Dictionary<string, string>Optional headers to include in the telemetry. Only applicable for datasets with a destination of the MQTT broker.
cancellationToken
CancellationTokenCancellation token.
Returns
ForwardSampledDatasetAsync(string, string, Asset, string, AssetDataset, byte[], Dictionary<string, string>?, CancellationToken)
Push a sampled dataset to the configured destinations.
public Task ForwardSampledDatasetAsync(string deviceName, string inboundEndpointName, Asset asset, string assetName, AssetDataset dataset, byte[] serializedPayload, Dictionary<string, string>? userData = null, CancellationToken cancellationToken = default)
Parameters
deviceName
stringThe name of the device that this dataset belongs to
inboundEndpointName
stringThe name of the inbound endpoint that this dataset belongs to
asset
AssetThe asset that the dataset belongs to.
assetName
stringThe name of the asset that the dataset belongs to
dataset
AssetDatasetThe dataset that was sampled.
serializedPayload
byte[]The payload to push to the configured destinations.
userData
Dictionary<string, string>Optional headers to include in the telemetry. Only applicable for datasets with a destination of the MQTT broker.
cancellationToken
CancellationTokenCancellation token.
Returns
RunConnectorAsync(CancellationToken)
Run the connector worker.
public override Task RunConnectorAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenCancellation token.
Returns
Remarks
This will run the connector until the provided cancellation token is cancelled.