Table of Contents

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)

  1. 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.
  2. 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

azureDeviceRegistryClient IAzureDeviceRegistryClient

The Azure Device Registry client used to send these runtime health events.

deviceName string

The name of the device.

inboundEndpointName string

The name of the inbound endpoint

reportingPeriod TimeSpan?

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

cancellationToken CancellationToken

Cancellation token.

Returns

Task

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

disposing bool

Returns

ValueTask

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

deviceEndpointRuntimeHealth RuntimeHealth

The device endpoint's runtime health.

telemetryTimeout TimeSpan?

The timeout for sending this telemetry. This value is ignored if the runtime health isn't ruled worth sending.

cancellationToken CancellationToken

Cancellation token

Returns

Task

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.