Skip to content

Commit

Permalink
API accessors and naming updates
Browse files Browse the repository at this point in the history
  • Loading branch information
drwill-ms committed Oct 17, 2022
1 parent b2fc709 commit ac5959f
Show file tree
Hide file tree
Showing 45 changed files with 136 additions and 128 deletions.
2 changes: 2 additions & 0 deletions SDK v2 migration guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ but users are still encouraged to migrate to version 2 when they have the chance
| Version 1 API | Equivalent version 2 API |
|:---|:---|
| `DeviceClient` | `IotHubDeviceClient` |
| `DeviceClient.SendEventAsync` | `IotHubDeviceClient.SendTelemetryAsync` |
| `DeviceClient.SendEventBatchAsync` | `IotHubDeviceClient.SendTelemetryBatchAsync` |
| `SetConnectionStatusChangesHandler` | `SetConnectionStatusChangeHandler` |
| `MessageResponse` | `MessageAcknowledgement` |
| `Message` | `IncomingMessage`, `OutgoingMessage` |
Expand Down
4 changes: 2 additions & 2 deletions e2e/test/helpers/TestDeviceCallbackHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ public async Task WaitForTwinCallbackAsync(CancellationToken ct)
public async Task SetMessageReceiveCallbackHandlerAsync()
{
await _deviceClient.OpenAsync().ConfigureAwait(false);
await _deviceClient.SetMessageCallbackAsync(OnC2dMessageReceivedAsync).ConfigureAwait(false);
await _deviceClient.SetIncomingMessageCallbackAsync(OnC2dMessageReceivedAsync).ConfigureAwait(false);
}

public async Task UnsetMessageReceiveCallbackHandlerAsync()
{
await _deviceClient.OpenAsync().ConfigureAwait(false);
await _deviceClient.SetMessageCallbackAsync(null).ConfigureAwait(false);
await _deviceClient.SetIncomingMessageCallbackAsync(null).ConfigureAwait(false);
}

private Task<MessageAcknowledgement> OnC2dMessageReceivedAsync(IncomingMessage message)
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/helpers/templates/FaultInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static bool FaultShouldDisconnect(string faultType)
faultDelay,
faultDuration);

await deviceClient.SendEventAsync(faultInjectionMessage, cts.Token).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(faultInjectionMessage, cts.Token).ConfigureAwait(false);
}
catch (Exception ex) when (ex is IotHubClientException hubEx && hubEx.IsTransient)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal static class FaultInjectionPoolingOverAmqp
logger.Trace($"{nameof(FaultInjectionPoolingOverAmqp)}: {testDevices.First().Id} Requesting fault injection type={faultType} reason={reason}, delay={faultDelay}, duration={faultDuration}");
faultInjectionDuration.Start();
OutgoingMessage faultInjectionMessage = FaultInjection.ComposeErrorInjectionProperties(faultType, reason, faultDelay, faultDuration);
await deviceClients.First().SendEventAsync(faultInjectionMessage).ConfigureAwait(false);
await deviceClients.First().SendTelemetryAsync(faultInjectionMessage).ConfigureAwait(false);

logger.Trace($"{nameof(FaultInjection)}: Waiting for fault injection to be active: {faultDelay} seconds.");
await Task.Delay(faultDelay).ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/CombinedClientOperationsPoolAmqpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async Task TestOperationAsync(IotHubDeviceClient deviceClient, TestDevice testDe
// D2C Operation
Logger.Trace($"{nameof(CombinedClientOperationsPoolAmqpTests)}: Operation 1: Send D2C for device={testDevice.Id}");
var message = MessageSendE2ETests.ComposeD2cTestMessage(Logger, out string _, out string _);
Task sendD2cMessage = deviceClient.SendEventAsync(message);
Task sendD2cMessage = deviceClient.SendTelemetryAsync(message);
clientOperations.Add(sendD2cMessage);

// C2D Operation
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/DeviceClientX509AuthenticationE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private async Task SendMessageTestAsync(IotHubClientTransportSettings transportS
using IotHubDeviceClient deviceClient = testDevice.CreateDeviceClient(new IotHubClientOptions(transportSetting));
await deviceClient.OpenAsync().ConfigureAwait(false);
var message = MessageSendE2ETests.ComposeD2cTestMessage(Logger, out string _, out string _);
await deviceClient.SendEventAsync(message).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(message).ConfigureAwait(false);
await deviceClient.CloseAsync().ConfigureAwait(false);
}

Expand Down
10 changes: 5 additions & 5 deletions e2e/test/iothub/DeviceTokenRefreshE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public async Task IotHubDeviceClient_TokenConnectionDoubleRelease_Ok()

Logger.Trace($"{deviceId}: DeviceClient SendEventAsync.");
var testMessage = new OutgoingMessage("TestMessage");
await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);

Logger.Trace($"{deviceId}: DeviceClient CloseAsync.");
await deviceClient.CloseAsync().ConfigureAwait(false);
Expand Down Expand Up @@ -166,7 +166,7 @@ void ConnectionStatusChangeHandler(ConnectionStatusInfo connectionStatusInfo)
var timeout = TimeSpan.FromSeconds(sasTokenTimeToLive.TotalSeconds * 2);
using var cts1 = new CancellationTokenSource(timeout);
await deviceClient.OpenAsync().ConfigureAwait(false);
await deviceClient.SendEventAsync(message, cts1.Token).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(message, cts1.Token).ConfigureAwait(false);

// Wait for the Token to expire.

Expand All @@ -179,7 +179,7 @@ void ConnectionStatusChangeHandler(ConnectionStatusInfo connectionStatusInfo)
// Test that the client is able to send messages
Logger.Trace($"[{testDevice.Id}]: SendEventAsync (2)");
using var cts2 = new CancellationTokenSource(timeout);
await deviceClient.SendEventAsync(message, cts2.Token).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(message, cts2.Token).ConfigureAwait(false);
}

private async Task IotHubDeviceClient_TokenIsRefreshed_Internal(IotHubClientTransportSettings transportSettings, TimeSpan ttl)
Expand Down Expand Up @@ -228,7 +228,7 @@ void ConnectionStatusChangeHandler(ConnectionStatusInfo connectionStatusInfo)
await deviceClient.OpenAsync(cts.Token).ConfigureAwait(false);

Logger.Trace($"[{DateTime.UtcNow}] SendEventAsync (1)");
await deviceClient.SendEventAsync(message, cts.Token).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(message, cts.Token).ConfigureAwait(false);
await refresher.WaitForTokenRefreshAsync(cts.Token).ConfigureAwait(false);
}
catch (OperationCanceledException ex)
Expand All @@ -254,7 +254,7 @@ void ConnectionStatusChangeHandler(ConnectionStatusInfo connectionStatusInfo)
try
{
Logger.Trace($"[{DateTime.UtcNow}] SendEventAsync (2)");
await deviceClient.SendEventAsync(message, cts.Token).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(message, cts.Token).ConfigureAwait(false);
await refresher.WaitForTokenRefreshAsync(cts.Token).ConfigureAwait(false);
}
catch (OperationCanceledException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ private async Task TestSecurityMessageModuleAsync(IotHubClientTransportSettings
await deviceClient.OpenAsync().ConfigureAwait(false);

OutgoingMessage testMessage = ComposeD2CSecurityTestMessage();
await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);
}

private async Task SendSingleSecurityMessageModuleAsync(
IotHubModuleClient moduleClient)
{
await moduleClient.OpenAsync().ConfigureAwait(false);
OutgoingMessage testMessage = ComposeD2CSecurityTestMessage();
await moduleClient.SendEventAsync(testMessage).ConfigureAwait(false);
await moduleClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);
}

protected override void Dispose(bool disposing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ async Task TestOperationAsync(IotHubDeviceClient deviceClient, TestDevice testDe

Logger.Trace($"{nameof(FaultInjectionPoolAmqpTests)}.{testDevice.Id}: payload='{payload}' p1Value='{p1Value}'");
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(20));
await deviceClient.SendEventAsync(testMessage, cts.Token).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage, cts.Token).ConfigureAwait(false);
}

await FaultInjectionPoolingOverAmqp
Expand Down
4 changes: 2 additions & 2 deletions e2e/test/iothub/messaging/MessageReceiveE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static async Task VerifyReceivedC2dMessageAsync(IotHubDeviceClient dc, st
c2dMessageReceived.TrySetResult(message);
return Task.FromResult(MessageAcknowledgement.Complete);
};
await dc.SetMessageCallbackAsync(OnC2DMessageReceived).ConfigureAwait(false);
await dc.SetIncomingMessageCallbackAsync(OnC2DMessageReceived).ConfigureAwait(false);

IncomingMessage receivedMessage = await TaskCompletionSourceHelper.GetTaskCompletionSourceResultAsync(c2dMessageReceived, cts.Token).ConfigureAwait(false);

Expand Down Expand Up @@ -319,7 +319,7 @@ void ConnectionStatusChangeHandler(ConnectionStatusInfo connectionStatusInfo)

// This will make the client unsubscribe from the mqtt c2d topic/close the amqp c2d link. Neither event
// should close the connection as a whole, though.
await deviceClient.SetMessageCallbackAsync(null).ConfigureAwait(false);
await deviceClient.SetIncomingMessageCallbackAsync(null).ConfigureAwait(false);

await Task.Delay(1000).ConfigureAwait(false);

Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/messaging/MessageSendE2EPoolAmqpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async Task TestOperationAsync(IotHubDeviceClient deviceClient, TestDevice testDe
{
OutgoingMessage testMessage = MessageSendE2ETests.ComposeD2cTestMessage(Logger, out string payload, out string p1Value);
Logger.Trace($"{nameof(MessageSendE2EPoolAmqpTests)}.{testDevice.Id}: messageId='{testMessage.MessageId}' payload='{payload}' p1Value='{p1Value}'");
await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);
}

await PoolingOverAmqp
Expand Down
6 changes: 3 additions & 3 deletions e2e/test/iothub/messaging/MessageSendE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static async Task SendSingleMessageAsync(IotHubDeviceClient deviceClient,
? ComposeD2cTestMessage(logger, out string _, out string _)
: ComposeD2cTestMessageOfSpecifiedSize(messageSize, logger, out string _, out string _);

await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);
}

public static async Task SendBatchMessagesAsync(IotHubDeviceClient deviceClient, MsTestLogger logger)
Expand All @@ -218,14 +218,14 @@ public static async Task SendBatchMessagesAsync(IotHubDeviceClient deviceClient,
}

await deviceClient.OpenAsync().ConfigureAwait(false);
await deviceClient.SendEventBatchAsync(messagesToBeSent.Keys.ToList()).ConfigureAwait(false);
await deviceClient.SendTelemetryBatchAsync(messagesToBeSent.Keys.ToList()).ConfigureAwait(false);
}

private async Task SendSingleMessageModuleAsync(IotHubModuleClient moduleClient)
{
OutgoingMessage testMessage = ComposeD2cTestMessage(Logger, out string _, out string _);

await moduleClient.SendEventAsync(testMessage).ConfigureAwait(false);
await moduleClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);
}

private async Task OpenCloseOpenThenSendSingleMessage(TestDeviceType type, IotHubClientTransportSettings transportSettings, int messageSize = 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ async Task TestOperationAsync(IotHubDeviceClient deviceClient, TestDevice testDe
{
OutgoingMessage testMessage = MessageSendE2ETests.ComposeD2cTestMessage(Logger, out string _, out string _);
using var cts = new CancellationTokenSource(operationTimeout);
await deviceClient.SendEventAsync(testMessage, cts.Token).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage, cts.Token).ConfigureAwait(false);
};

await FaultInjection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private static async Task TestDeviceClientInvalidServiceCertificate(IotHubClient
new IotHubClientOptions(transportSettings));
var testMessage = new OutgoingMessage();
await deviceClient.OpenAsync().ConfigureAwait(false);
await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);
await deviceClient.CloseAsync().ConfigureAwait(false);
}
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/iothub/service/MessageFeedbackReceiverE2ETest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task MessageFeedbackReceiver_Operation(IotHubTransportProtocol prot
c2dMessageReceived.TrySetResult(true);
return Task.FromResult(MessageAcknowledgement.Complete);
};
await deviceClient.SetMessageCallbackAsync(OnC2DMessageReceived).ConfigureAwait(false);
await deviceClient.SetIncomingMessageCallbackAsync(OnC2DMessageReceived).ConfigureAwait(false);

await Task
.WhenAny(
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/provisioning/ProvisioningE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ public static ProvisioningClientOptions CreateProvisioningClientOptionsFromName(
Logger.Trace("DeviceClient SendEventAsync.");

var testMessage = new OutgoingMessage("TestMessage");
await iotClient.SendEventAsync(testMessage).ConfigureAwait(false);
await iotClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);

if (sendReportedPropertiesUpdate)
{
Expand Down
4 changes: 2 additions & 2 deletions e2e/test/provisioning/ReprovisioningE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public async Task ProvisioningDeviceClient_ReprovisioningBlockingWorks_MqttWs_Sy
Logger.Trace("DeviceClient SendEventAsync.");

var message = new OutgoingMessage("TestMessage");
await deviceClient.SendEventAsync(message).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(message).ConfigureAwait(false);

if (transportProtocolSupportsTwinOperations)
{
Expand Down Expand Up @@ -879,7 +879,7 @@ await RetryOperationHelper
Logger.Trace("DeviceClient SendEventAsync.");

var testMessage = new OutgoingMessage("TestMessage");
await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);
await deviceClient.SendTelemetryAsync(testMessage).ConfigureAwait(false);

// Twin can be configured to revert back to default twin when provisioned, or to keep twin
// from previous hub's records.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task RunSampleAsync()
await _deviceClient.OpenAsync(cts.Token);

// Now subscribe to receive C2D messages through a callback (which isn't supported over HTTP).
await _deviceClient.SetMessageCallbackAsync(OnC2dMessageReceivedAsync);
await _deviceClient.SetIncomingMessageCallbackAsync(OnC2dMessageReceivedAsync);
Console.WriteLine($"\n{DateTime.Now}> Subscribed to receive C2D messages over callback.");

// Now wait to receive C2D messages through the callback.
Expand All @@ -57,7 +57,7 @@ public async Task RunSampleAsync()
}

// Now unsubscibe from receiving the callback.
await _deviceClient.SetMessageCallbackAsync(null);
await _deviceClient.SetIncomingMessageCallbackAsync(null);
}

private Task<MessageAcknowledgement> OnC2dMessageReceivedAsync(IncomingMessage receivedMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private static async Task SendDeviceToCloudMessagesAsync(IotHubDeviceClient devi
try
{
// Submit the message to the hub.
await deviceClient.SendEventAsync(message, token);
await deviceClient.SendTelemetryAsync(message, token);

// Print out the message.
Console.WriteLine("{0} > Sent message: {1}", DateTime.UtcNow, JsonConvert.SerializeObject(telemetryDataPoint));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private static async Task SendDeviceToCloudMessagesAsync(IotHubDeviceClient devi
{
await deviceClient.OpenAsync(token);
// Submit the message to the hub.
await deviceClient.SendEventAsync(message, token);
await deviceClient.SendTelemetryAsync(message, token);

// Print out the message.
Console.WriteLine("{0} > Sent message: {1}", DateTime.Now, JsonConvert.SerializeObject(telemetryDataPoint));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static async Task SendDeviceToCloudMessagesAsync(IotHubDeviceClient devi

await deviceClient.OpenAsync(ct);
// Send the telemetry message
await deviceClient.SendEventAsync(message, ct);
await deviceClient.SendTelemetryAsync(message, ct);
Console.WriteLine($"{DateTime.Now} > Sending message: {JsonConvert.SerializeObject(telemetryDataPoint)}");

await Task.Delay(1000, ct);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private async Task SendDeviceToCloudMessagesAsync(CancellationToken ct)
message.Properties.Add("temperatureAlert", (currentTemperature > 30) ? "true" : "false");

// Send the telemetry message.
await _deviceClient.SendEventAsync(message, ct);
await _deviceClient.SendTelemetryAsync(message, ct);
Console.WriteLine($"{DateTime.Now} > Sending message: {JsonConvert.SerializeObject(telemetryDataPoint)}");

await Task.Delay(s_telemetryInterval, ct);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private async Task InitializeAndSetupClientAsync(CancellationToken cancellationT
}

// You will need to resubscribe to any client callbacks any time the client is initialized.
await s_deviceClient.SetMessageCallbackAsync(OnMessageReceivedAsync, cancellationToken);
await s_deviceClient.SetIncomingMessageCallbackAsync(OnMessageReceivedAsync, cancellationToken);
_logger.LogDebug("The client has subscribed to cloud-to-device messages.");

await s_deviceClient.SetDesiredPropertyUpdateCallbackAsync(HandleTwinUpdateNotificationsAsync, cancellationToken);
Expand Down Expand Up @@ -247,7 +247,7 @@ private async Task SendMessagesAsync(CancellationToken cancellationToken)
_logger.LogInformation($"Device sending message {++messageCount} to IoT hub.");

OutgoingMessage message = PrepareMessage(messageCount);
await s_deviceClient.SendEventAsync(message, cancellationToken);
await s_deviceClient.SendTelemetryAsync(message, cancellationToken);
_logger.LogInformation($"Device sent message {messageCount} to IoT hub.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private async Task SendTelemetry()
string telemetryPayload = "{{ \"temperature\": 0d }}";
var message = new OutgoingMessage(telemetryPayload);

await _deviceClient.SendEventAsync(message);
await _deviceClient.SendTelemetryAsync(message);
}
}
}

0 comments on commit ac5959f

Please sign in to comment.