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
applicationContextApplicationContextloggerILogger<ConnectorWorker>mqttClientIMqttClientmessageSchemaProviderFactoryIMessageSchemaProvideradrClientWrapperFactoryIAdrClientWrapperProviderleaderElectionConfigurationProviderIConnectorLeaderElectionConfigurationProvider
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
cancellationTokenCancellationToken
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
deviceNamestringThe name of the device that this event belongs to
inboundEndpointNamestringThe name of the inbound endpoint that this event belongs to
assetAssetThe asset that this event came from.
assetNamestringThe name of the asset that this event belongs to.
assetEventAssetEventThe event.
serializedPayloadbyte[]The payload to push to the configured destinations.
userDataDictionary<string, string>Optional headers to include in the telemetry. Only applicable for datasets with a destination of the MQTT broker.
cancellationTokenCancellationTokenCancellation 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
deviceNamestringThe name of the device that this dataset belongs to
inboundEndpointNamestringThe name of the inbound endpoint that this dataset belongs to
assetAssetThe asset that the dataset belongs to.
assetNamestringThe name of the asset that the dataset belongs to
datasetAssetDatasetThe dataset that was sampled.
serializedPayloadbyte[]The payload to push to the configured destinations.
userDataDictionary<string, string>Optional headers to include in the telemetry. Only applicable for datasets with a destination of the MQTT broker.
cancellationTokenCancellationTokenCancellation token.
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.