Table of Contents

Class AssetClient

Namespace
Azure.Iot.Operations.Connector
Assembly
Azure.Iot.Operations.Connector.dll

A client for updating the status of an asset and for forwarding received events and/or sampled datasets.

public class AssetClient : IAsyncDisposable
Inheritance
AssetClient
Implements
Inherited Members

Methods

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public virtual ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

DisposeAsync(bool)

public virtual ValueTask DisposeAsync(bool disposing)

Parameters

disposing bool

Returns

ValueTask

ForwardReceivedEventAsync(string, AssetEvent, byte[], Dictionary<string, string>?, string?, CancellationToken)

Push a received event payload to the configured destinations.

public Task ForwardReceivedEventAsync(string eventGroupName, AssetEvent assetEvent, byte[] serializedPayload, Dictionary<string, string>? userData = null, string? protocolSpecificIdentifier = null, CancellationToken cancellationToken = default)

Parameters

eventGroupName string

The name of the event group 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.

protocolSpecificIdentifier string

Optional protocol specific identifier.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

ForwardSampledDatasetAsync(AssetDataset, byte[], Dictionary<string, string>?, string?, CancellationToken)

Push a sampled dataset to the configured destinations.

public Task ForwardSampledDatasetAsync(AssetDataset dataset, byte[] serializedPayload, Dictionary<string, string>? userData = null, string? protocolSpecificIdentifier = null, CancellationToken cancellationToken = default)

Parameters

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.

protocolSpecificIdentifier string

Optional protocol specific identifier.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

GetAndUpdateAssetStatusAsync(Func<AssetStatus, AssetStatus?>, bool, TimeSpan?, CancellationToken)

Get the current status of this asset and then optionally update it.

public Task<AssetStatus> GetAndUpdateAssetStatusAsync(Func<AssetStatus, AssetStatus?> handler, bool onlyIfChanged = false, TimeSpan? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

handler Func<AssetStatus, AssetStatus>

The function that determines the new asset status when given the current asset status.

onlyIfChanged bool

Only send the status update if the new status is different from the current status. If the only difference between the current and new status is a 'LastTransitionTime' field, then the statuses will be considered identical.

commandTimeout TimeSpan?

The timeout for each of the 'get' and 'update' commands.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<AssetStatus>

The latest asset status after this operation.

Remarks

If after retrieving the current status, you don't want to send any updates, handler should return null. If this happens, this function will return the latest asset status without trying to update it.

This method uses a semaphore to ensure that this same client doesn't accidentally update the asset status while another thread is in the middle of updating the same asset. This ensures that the current device status provided in handler stays accurate while any updating occurs.

GetRegisteredDatasetMessageSchema(string)

public MessageSchemaReference? GetRegisteredDatasetMessageSchema(string datasetName)

Parameters

datasetName string

Returns

MessageSchemaReference

GetRegisteredEventMessageSchema(string, string)

public MessageSchemaReference? GetRegisteredEventMessageSchema(string eventGroupName, string eventName)

Parameters

eventGroupName string
eventName string

Returns

MessageSchemaReference

ReportDatasetRuntimeHealthAsync(List<ConnectorDatasetsRuntimeHealthEvent>, TimeSpan?, CancellationToken)

Report a batch of datasets' runtime healths.

public Task ReportDatasetRuntimeHealthAsync(List<ConnectorDatasetsRuntimeHealthEvent> runtimeHealth, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)

Parameters

runtimeHealth List<ConnectorDatasetsRuntimeHealthEvent>

The runtime healths of some datasets.

telemetryTimeout TimeSpan?

The timeout to use when sending this telemetry if any telemetry is sent.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

Remarks

This method uses the AssetRuntimeHealthReporter class, so it will de-duplicate runtime healths and will periodically report the last known runtime health for as long as this asset is available. Because of that, connector applications can freely call this method repeatedly even if the runtime health hasn't changed.

ReportDatasetRuntimeHealthAsync(string, ConnectorRuntimeHealth, TimeSpan?, CancellationToken)

Report a dataset's runtime health.

public Task ReportDatasetRuntimeHealthAsync(string datasetName, ConnectorRuntimeHealth runtimeHealth, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)

Parameters

datasetName string

The name of the dataset

runtimeHealth ConnectorRuntimeHealth

The runtime health of this dataset.

telemetryTimeout TimeSpan?

The timeout to use when sending this telemetry if any telemetry is sent.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

Remarks

This method uses the AssetRuntimeHealthReporter class, so it will de-duplicate runtime healths and will periodically report the last known runtime health for as long as this asset is available. Because of that, connector applications can freely call this method repeatedly even if the runtime health hasn't changed.

ReportEventRuntimeHealthAsync(List<ConnectorEventsRuntimeHealthEvent>, TimeSpan?, CancellationToken)

Report a batch of events' runtime healths.

public Task ReportEventRuntimeHealthAsync(List<ConnectorEventsRuntimeHealthEvent> runtimeHealth, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)

Parameters

runtimeHealth List<ConnectorEventsRuntimeHealthEvent>

The runtime healths of some events.

telemetryTimeout TimeSpan?

The timeout to use when sending this telemetry if any telemetry is sent.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

Remarks

This method uses the AssetRuntimeHealthReporter class, so it will de-duplicate runtime healths and will periodically report the last known runtime health for as long as this asset is available. Because of that, connector applications can freely call this method repeatedly even if the runtime health hasn't changed.

ReportEventRuntimeHealthAsync(string, string, ConnectorRuntimeHealth, TimeSpan?, CancellationToken)

Report an event's runtime health.

public Task ReportEventRuntimeHealthAsync(string eventGroupName, string eventName, ConnectorRuntimeHealth runtimeHealth, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)

Parameters

eventGroupName string

The name of the event group that this event belongs to

eventName string

The name of the event

runtimeHealth ConnectorRuntimeHealth

The runtime health of this event.

telemetryTimeout TimeSpan?

The timeout to use when sending this telemetry if any telemetry is sent.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

Remarks

This method uses the AssetRuntimeHealthReporter class, so it will de-duplicate runtime healths and will periodically report the last known runtime health for as long as this asset is available. Because of that, connector applications can freely call this method repeatedly even if the runtime health hasn't changed.

ReportManagementActionRuntimeHealthAsync(List<ConnectorManagementActionsRuntimeHealthEvent>, TimeSpan?, CancellationToken)

Report a batch of management actions' runtime healths.

public Task ReportManagementActionRuntimeHealthAsync(List<ConnectorManagementActionsRuntimeHealthEvent> runtimeHealth, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)

Parameters

runtimeHealth List<ConnectorManagementActionsRuntimeHealthEvent>

The runtime healths of some management actions.

telemetryTimeout TimeSpan?

The timeout to use when sending this telemetry if any telemetry is sent.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

Remarks

This method uses the AssetRuntimeHealthReporter class, so it will de-duplicate runtime healths and will periodically report the last known runtime health for as long as this asset is available. Because of that, connector applications can freely call this method repeatedly even if the runtime health hasn't changed.

ReportManagementActionRuntimeHealthAsync(string, string, ConnectorRuntimeHealth, TimeSpan?, CancellationToken)

Report a management action's runtime health.

public Task ReportManagementActionRuntimeHealthAsync(string managementGroupName, string managementActionName, ConnectorRuntimeHealth runtimeHealth, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)

Parameters

managementGroupName string

The name of the management group that this action belongs to

managementActionName string

The name of the management action

runtimeHealth ConnectorRuntimeHealth

The runtime health of this management action.

telemetryTimeout TimeSpan?

The timeout to use when sending this telemetry if any telemetry is sent.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

Remarks

This method uses the AssetRuntimeHealthReporter class, so it will de-duplicate runtime healths and will periodically report the last known runtime health for as long as this asset is available. Because of that, connector applications can freely call this method repeatedly even if the runtime health hasn't changed.

ReportStreamRuntimeHealthAsync(List<ConnectorStreamsRuntimeHealthEvent>, TimeSpan?, CancellationToken)

Report a batch of streams' runtime healths.

public Task ReportStreamRuntimeHealthAsync(List<ConnectorStreamsRuntimeHealthEvent> runtimeHealth, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)

Parameters

runtimeHealth List<ConnectorStreamsRuntimeHealthEvent>

The runtime healths of some streams.

telemetryTimeout TimeSpan?

The timeout to use when sending this telemetry if any telemetry is sent.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

Remarks

This method uses the AssetRuntimeHealthReporter class, so it will de-duplicate runtime healths and will periodically report the last known runtime health for as long as this asset is available. Because of that, connector applications can freely call this method repeatedly even if the runtime health hasn't changed.

ReportStreamRuntimeHealthAsync(string, ConnectorRuntimeHealth, TimeSpan?, CancellationToken)

Report a stream's runtime health.

public Task ReportStreamRuntimeHealthAsync(string streamName, ConnectorRuntimeHealth runtimeHealth, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)

Parameters

streamName string

The name of the stream

runtimeHealth ConnectorRuntimeHealth

The runtime health of this stream.

telemetryTimeout TimeSpan?

The timeout to use when sending this telemetry if any telemetry is sent.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

Remarks

This method uses the AssetRuntimeHealthReporter class, so it will de-duplicate runtime healths and will periodically report the last known runtime health for as long as this asset is available. Because of that, connector applications can freely call this method repeatedly even if the runtime health hasn't changed.

SetRuntimeHealthBackgroundReportingIntervalAsync(TimeSpan, CancellationToken)

Change the interval at which this client will send background reports of the latest cached asset runtime healths

public Task SetRuntimeHealthBackgroundReportingIntervalAsync(TimeSpan reportingInterval, CancellationToken cancellationToken = default)

Parameters

reportingInterval TimeSpan

The new reporting interval

cancellationToken CancellationToken

Cancellation token

Returns

Task

Remarks

If background reporting is currently in progress, it will be cancelled and restarted with this new interval. If background reporting is not currently in progress, calling this method will not start it.