Class DeviceEndpointRuntimeHealthReporter
- Namespace
- Azure.Iot.Operations.Services.AssetAndDeviceRegistry
- Assembly
- Azure.Iot.Operations.Services.dll
A class for smartly sending runtime health events for a specific device endpoint to the Azure Device Registry service
public class DeviceEndpointRuntimeHealthReporter : IAsyncDisposable
- Inheritance
-
DeviceEndpointRuntimeHealthReporter
- Implements
- Inherited Members
Remarks
This class has two main features that differentiate it from just directly calling the runtime health update APIs like ReportDeviceEndpointRuntimeHealthAsync(string, string, RuntimeHealth, TimeSpan?, CancellationToken)
- De-duplication of device endpoint runtime healths. This allows you to write your connector code such that it repeatedly calls an API like ReportDeviceEndpointRuntimeHealthAsync(RuntimeHealth, TimeSpan?, CancellationToken) even if the runtime health has not changed as this client will cache the last sent runtime health and check if the new runtime health actually needs to be forwarded to the service.
- Periodic reporting of the last known runtime healths of the device endpoint with updated timestamps. Connectors are advised to periodically send these updates to ensure that the Azure Device Registry service has an up-to-date picture of the runtime health of each device endpoint and this class handles that for you. Additionally, the periodic updates can be paused when the device endpoint's runtime health becomes unknown. This background reporting period can be changed with SetRuntimeHealthBackgroundReportingIntervalAsync(TimeSpan, CancellationToken).
Constructors
DeviceEndpointRuntimeHealthReporter(IAzureDeviceRegistryClient, string, string, TimeSpan?)
Create a new runtime health reporter for a given device endpoint
public DeviceEndpointRuntimeHealthReporter(IAzureDeviceRegistryClient azureDeviceRegistryClient, string deviceName, string inboundEndpointName, TimeSpan? reportingPeriod = null)
Parameters
azureDeviceRegistryClientIAzureDeviceRegistryClientThe Azure Device Registry client used to send these runtime health events.
deviceNamestringThe name of the device.
inboundEndpointNamestringThe name of the inbound endpoint
reportingPeriodTimeSpan?The interval at which to send background reports.
Remarks
Background reporting does not start until the first call to ReportDeviceEndpointRuntimeHealthAsync(RuntimeHealth, TimeSpan?, CancellationToken).
Methods
CancelHealthStatusReportingAsync(CancellationToken)
Stop the background reporting of this device endpoint
public Task CancelHealthStatusReportingAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
Generally, this should be done if the runtime health of the device endpoint becomes unknown.
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
ReportDeviceEndpointRuntimeHealthAsync(RuntimeHealth, TimeSpan?, CancellationToken)
Report this device endpoint's runtime health if it is worth reporting compared to the previously sent runtime health.
public Task ReportDeviceEndpointRuntimeHealthAsync(RuntimeHealth deviceEndpointRuntimeHealth, TimeSpan? telemetryTimeout = null, CancellationToken cancellationToken = default)
Parameters
deviceEndpointRuntimeHealthRuntimeHealthThe device endpoint's runtime health.
telemetryTimeoutTimeSpan?The timeout for sending this telemetry. This value is ignored if the runtime health isn't ruled worth sending.
cancellationTokenCancellationTokenCancellation token
Returns
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.