/// <inheritdoc/>
 public Task SendAsync(string deviceId, string moduleId,
                       DeviceMessageModel message)
 {
     if (message == null)
     {
         throw new ArgumentNullException(nameof(message));
     }
     if (string.IsNullOrEmpty(deviceId))
     {
         throw new ArgumentNullException(nameof(deviceId));
     }
     return(Retry.WithExponentialBackoff(_logger, async() => {
         var to = $"/devices/{ToResourceId(deviceId, moduleId)}/messages/events";
         var request = NewRequest(to);
         foreach (var property in message.Properties)
         {
             if (kHeaderMap.TryGetValue(property.Key, out var header))
             {
                 request.AddHeader(header, property.Value);
             }
             else
             {
                 request.AddHeader(kHttpAppPropertyPrefix + property.Key,
                                   property.Value);
             }
         }
         request.AddHeader("iothub-operation", "d2c");
         request.AddHeader("iothub-to", to);
         request.SetContent(message.Payload);
         var response = await _httpClient.PostAsync(request);
         response.Validate();
     }));
Example #2
0
 /// <summary>
 /// Send messages for device
 /// </summary>
 /// <param name="service"></param>
 /// <param name="deviceId"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static Task SendAsync(this IIoTHubMessagingServices service,
                              string deviceId, DeviceMessageModel message) =>
 service.SendAsync(deviceId, null, message);