DigitalTwinsClient.PublishTelemetryAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Publishes telemetry from a digital twin asynchronously. The result is then consumed by one or many destination endpoints (subscribers) defined under DigitalTwinsEventRoute. These event routes need to be set before publishing a telemetry message, in order for the telemetry message to be consumed.
public virtual System.Threading.Tasks.Task<Azure.Response> PublishTelemetryAsync (string digitalTwinId, string messageId, string payload, DateTimeOffset? timestamp = default, System.Threading.CancellationToken cancellationToken = default);
abstract member PublishTelemetryAsync : string * string * string * Nullable<DateTimeOffset> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response>
override this.PublishTelemetryAsync : string * string * string * Nullable<DateTimeOffset> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function PublishTelemetryAsync (digitalTwinId As String, messageId As String, payload As String, Optional timestamp As Nullable(Of DateTimeOffset) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response)
Parameters
- digitalTwinId
- String
The Id of the digital twin.
- messageId
- String
A unique message identifier (within the scope of the digital twin id) that is commonly used for de-duplicating messages. Defaults to a random GUID if argument is null.
- payload
- String
The application/json telemetry payload to be sent.
- timestamp
- Nullable<DateTimeOffset>
An RFC 3339 timestamp that identifies the time the telemetry was measured. It defaults to the current date/time UTC.
- cancellationToken
- CancellationToken
The cancellation token.
Returns
The HTTP response Response.
Exceptions
The exception that captures the errors from the service. Check the ErrorCode and Status properties for more details.
The exception is thrown when digitalTwinId
or payload
is null
.
Examples
// construct your json telemetry payload by hand.
await client.PublishTelemetryAsync(twinId, Guid.NewGuid().ToString(), "{\"Telemetry1\": 5}");
Console.WriteLine($"Published telemetry message to twin '{twinId}'.");
Remarks
For more samples, see our repo samples.
Applies to
See also
Azure SDK for .NET