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
disposingbool
Returns
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
eventGroupNamestringThe name of the event group 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.
protocolSpecificIdentifierstringOptional protocol specific identifier.
cancellationTokenCancellationTokenCancellation token.
Returns
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
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.
protocolSpecificIdentifierstringOptional protocol specific identifier.
cancellationTokenCancellationTokenCancellation token.
Returns
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
handlerFunc<AssetStatus, AssetStatus>The function that determines the new asset status when given the current asset status.
onlyIfChangedboolOnly 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.
commandTimeoutTimeSpan?The timeout for each of the 'get' and 'update' commands.
cancellationTokenCancellationTokenCancellation 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
datasetNamestring
Returns
GetRegisteredEventMessageSchema(string, string)
public MessageSchemaReference? GetRegisteredEventMessageSchema(string eventGroupName, string eventName)
Parameters
Returns
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
runtimeHealthList<ConnectorDatasetsRuntimeHealthEvent>The runtime healths of some datasets.
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry if any telemetry is sent.
cancellationTokenCancellationTokenCancellation token.
Returns
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
datasetNamestringThe name of the dataset
runtimeHealthConnectorRuntimeHealthThe runtime health of this dataset.
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry if any telemetry is sent.
cancellationTokenCancellationTokenCancellation token.
Returns
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
runtimeHealthList<ConnectorEventsRuntimeHealthEvent>The runtime healths of some events.
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry if any telemetry is sent.
cancellationTokenCancellationTokenCancellation token.
Returns
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
eventGroupNamestringThe name of the event group that this event belongs to
eventNamestringThe name of the event
runtimeHealthConnectorRuntimeHealthThe runtime health of this event.
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry if any telemetry is sent.
cancellationTokenCancellationTokenCancellation token.
Returns
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
runtimeHealthList<ConnectorManagementActionsRuntimeHealthEvent>The runtime healths of some management actions.
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry if any telemetry is sent.
cancellationTokenCancellationTokenCancellation token.
Returns
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
managementGroupNamestringThe name of the management group that this action belongs to
managementActionNamestringThe name of the management action
runtimeHealthConnectorRuntimeHealthThe runtime health of this management action.
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry if any telemetry is sent.
cancellationTokenCancellationTokenCancellation token.
Returns
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
runtimeHealthList<ConnectorStreamsRuntimeHealthEvent>The runtime healths of some streams.
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry if any telemetry is sent.
cancellationTokenCancellationTokenCancellation token.
Returns
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
streamNamestringThe name of the stream
runtimeHealthConnectorRuntimeHealthThe runtime health of this stream.
telemetryTimeoutTimeSpan?The timeout to use when sending this telemetry if any telemetry is sent.
cancellationTokenCancellationTokenCancellation token.
Returns
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
reportingIntervalTimeSpanThe new reporting interval
cancellationTokenCancellationTokenCancellation token
Returns
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.