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, IAdrClientWrapperProvider, IConnectorLeaderElectionConfigurationProvider?)

public ConnectorWorker(ApplicationContext applicationContext, ILogger<ConnectorWorker> logger, IMqttClient mqttClient, IMessageSchemaProvider messageSchemaProviderFactory, IAdrClientWrapperProvider adrClientWrapperFactory, IConnectorLeaderElectionConfigurationProvider? leaderElectionConfigurationProvider = null)

Parameters

applicationContext ApplicationContext
logger ILogger<ConnectorWorker>
mqttClient IMqttClient
messageSchemaProviderFactory IMessageSchemaProvider
adrClientWrapperFactory IAdrClientWrapperProvider
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).

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).

_adrClient

protected IAdrClientWrapper? _adrClient

Field Value

IAdrClientWrapper

_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.

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 string

The name of the device that this event belongs to

inboundEndpointName string

The name of the inbound endpoint that this event belongs to

asset Asset

The asset that this event came from.

assetName string

The name of the asset that this event belongs to.

assetEvent AssetEvent

The 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 CancellationToken

Cancellation token.

Returns

Task

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 string

The name of the device that this dataset belongs to

inboundEndpointName string

The name of the inbound endpoint that this dataset belongs to

asset Asset

The asset that the dataset belongs to.

assetName string

The name of the asset that the dataset belongs to

dataset AssetDataset

The 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 CancellationToken

Cancellation token.

Returns

Task

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.