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
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)