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 : IDisposable
Inheritance
AssetClient
Implements
Inherited Members

Methods

Dispose()

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

public void Dispose()

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