From bea9936cdfd8ff524dc7d351cc355f5fdfff18d4 Mon Sep 17 00:00:00 2001 From: David Justo Date: Thu, 30 May 2024 10:01:45 -0700 Subject: [PATCH] delay decoding message contents --- .../Storage/QueueMessage.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/DurableTask.AzureStorage/Storage/QueueMessage.cs b/src/DurableTask.AzureStorage/Storage/QueueMessage.cs index df8f166e8..2f71fc32f 100644 --- a/src/DurableTask.AzureStorage/Storage/QueueMessage.cs +++ b/src/DurableTask.AzureStorage/Storage/QueueMessage.cs @@ -21,20 +21,27 @@ class QueueMessage public QueueMessage(CloudQueueMessage cloudQueueMessage) { this.CloudQueueMessage = cloudQueueMessage; - this.Message = this.CloudQueueMessage.AsString; this.Id = this.CloudQueueMessage.Id; } public QueueMessage(string message) { this.CloudQueueMessage = new CloudQueueMessage(message); - this.Message = this.CloudQueueMessage.AsString; this.Id = this.CloudQueueMessage.Id; } public CloudQueueMessage CloudQueueMessage { get; } - public string Message { get; } + public string Message { + get + { + // Obtaining the contents of a queueMessage can yield de-serializations exceptions. + // For example, if the message was encoded with a different encoding than the one used to decode it, this will throw. + // There are many cases where we don't actually need the message contents, such as when we're just trying to peek at the message's Age + // in the ScaleController. Therefore, we delay the decoding of the message until it's actually needed. + return this.CloudQueueMessage.AsString; + } + } public string Id { get; }