Skip to content

Commit ff4cea7

Browse files
authored
[Storage] BinaryData and encoding in Queues. (Azure#16689)
This is follow up on Azure#14476 . This PR takes initial work and adapts to use `System.BinaryData`
1 parent ce6b050 commit ff4cea7

35 files changed

+2457
-309
lines changed

sdk/storage/Azure.Storage.Queues/CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@
66
- Added CanGenerateSasUri property, GenerateSasUri() to QueueClient.
77
- Added CanGenerateAccountSasUri property, GenerateAccountSasUri() to QueueServiceClient.
88

9+
### Support for binary data, custom shapes and Base64 encoding
10+
This release adds a convinient way to send and receive binary data and custom shapes as a payload.
11+
Additionally, support for Base64 encoding in HTTP requests and reponses has been added that makes interoperability with V11 and prior Storage SDK easier to implement.
12+
13+
The `QueueClient.SendMessage` and `QueueClient.SendMessageAsync` consume `System.BinaryData` in addition to `string`.
14+
`QueueMessage` and `PeekedMessage` expose new property `Body` of `System.BinaryData` type to access message payload and should be used instead of `MessageText`.
15+
16+
See [System.BinaryData](https://github.com/Azure/azure-sdk-for-net/blob/System.Memory.Data_1.0.0/sdk/core/System.Memory.Data/README.md) for more information about handling `string`, binary data and custom shapes.
17+
18+
#### Receiving message as string
19+
Before:
20+
```C#
21+
QueueMessage message = await queueClient.ReceiveMessage();
22+
string messageText = message.MessageText;
23+
```
24+
25+
After:
26+
```C#
27+
QueueMessage message = await queueClient.ReceiveMessage();
28+
BinaryData body = message.Body;
29+
string messageText = body.ToString();
30+
```
31+
932
## 12.5.0-preview.1 (2020-09-30)
1033
- This preview contains bug fixes to improve quality.
1134

sdk/storage/Azure.Storage.Queues/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ queue.SendMessage("third");
8686
foreach (QueueMessage message in queue.ReceiveMessages(maxMessages: 10).Value)
8787
{
8888
// "Process" the message
89-
Console.WriteLine($"Message: {message.MessageText}");
89+
Console.WriteLine($"Message: {message.Body}");
9090

9191
// Let the service know we're finished with the message and
9292
// it can be safely deleted.

sdk/storage/Azure.Storage.Queues/api/Azure.Storage.Queues.netstandard2.0.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,28 @@ public QueueClient(System.Uri queueUri, Azure.Storage.StorageSharedKeyCredential
4747
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Queues.Models.QueueMessage[]>> ReceiveMessagesAsync() { throw null; }
4848
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Queues.Models.QueueMessage[]>> ReceiveMessagesAsync(int? maxMessages = default(int?), System.TimeSpan? visibilityTimeout = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
4949
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Queues.Models.QueueMessage[]>> ReceiveMessagesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
50+
public virtual Azure.Response<Azure.Storage.Queues.Models.SendReceipt> SendMessage(System.BinaryData message, System.TimeSpan? visibilityTimeout = default(System.TimeSpan?), System.TimeSpan? timeToLive = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
5051
public virtual Azure.Response<Azure.Storage.Queues.Models.SendReceipt> SendMessage(string messageText) { throw null; }
5152
public virtual Azure.Response<Azure.Storage.Queues.Models.SendReceipt> SendMessage(string messageText, System.TimeSpan? visibilityTimeout = default(System.TimeSpan?), System.TimeSpan? timeToLive = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
5253
public virtual Azure.Response<Azure.Storage.Queues.Models.SendReceipt> SendMessage(string messageText, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
54+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Queues.Models.SendReceipt>> SendMessageAsync(System.BinaryData message, System.TimeSpan? visibilityTimeout = default(System.TimeSpan?), System.TimeSpan? timeToLive = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
5355
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Queues.Models.SendReceipt>> SendMessageAsync(string messageText) { throw null; }
5456
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Queues.Models.SendReceipt>> SendMessageAsync(string messageText, System.TimeSpan? visibilityTimeout = default(System.TimeSpan?), System.TimeSpan? timeToLive = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
5557
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Queues.Models.SendReceipt>> SendMessageAsync(string messageText, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
5658
public virtual Azure.Response SetAccessPolicy(System.Collections.Generic.IEnumerable<Azure.Storage.Queues.Models.QueueSignedIdentifier> permissions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
5759
public virtual System.Threading.Tasks.Task<Azure.Response> SetAccessPolicyAsync(System.Collections.Generic.IEnumerable<Azure.Storage.Queues.Models.QueueSignedIdentifier> permissions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
5860
public virtual Azure.Response SetMetadata(System.Collections.Generic.IDictionary<string, string> metadata, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
5961
public virtual System.Threading.Tasks.Task<Azure.Response> SetMetadataAsync(System.Collections.Generic.IDictionary<string, string> metadata, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
62+
public virtual Azure.Response<Azure.Storage.Queues.Models.UpdateReceipt> UpdateMessage(string messageId, string popReceipt, System.BinaryData message, System.TimeSpan visibilityTimeout = default(System.TimeSpan), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
6063
public virtual Azure.Response<Azure.Storage.Queues.Models.UpdateReceipt> UpdateMessage(string messageId, string popReceipt, string messageText = null, System.TimeSpan visibilityTimeout = default(System.TimeSpan), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
64+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Queues.Models.UpdateReceipt>> UpdateMessageAsync(string messageId, string popReceipt, System.BinaryData message, System.TimeSpan visibilityTimeout = default(System.TimeSpan), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
6165
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Queues.Models.UpdateReceipt>> UpdateMessageAsync(string messageId, string popReceipt, string messageText = null, System.TimeSpan visibilityTimeout = default(System.TimeSpan), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
6266
}
6367
public partial class QueueClientOptions : Azure.Core.ClientOptions
6468
{
6569
public QueueClientOptions(Azure.Storage.Queues.QueueClientOptions.ServiceVersion version = Azure.Storage.Queues.QueueClientOptions.ServiceVersion.V2020_02_10) { }
6670
public System.Uri GeoRedundantSecondaryUri { get { throw null; } set { } }
71+
public Azure.Storage.Queues.QueueMessageEncoding MessageEncoding { get { throw null; } set { } }
6772
public Azure.Storage.Queues.QueueClientOptions.ServiceVersion Version { get { throw null; } }
6873
public enum ServiceVersion
6974
{
@@ -73,6 +78,11 @@ public enum ServiceVersion
7378
V2020_02_10 = 4,
7479
}
7580
}
81+
public enum QueueMessageEncoding
82+
{
83+
None = 0,
84+
Base64 = 1,
85+
}
7686
public partial class QueueServiceClient
7787
{
7888
protected QueueServiceClient() { }
@@ -121,10 +131,12 @@ namespace Azure.Storage.Queues.Models
121131
public partial class PeekedMessage
122132
{
123133
internal PeekedMessage() { }
134+
public System.BinaryData Body { get { throw null; } }
124135
public long DequeueCount { get { throw null; } }
125136
public System.DateTimeOffset? ExpiresOn { get { throw null; } }
126137
public System.DateTimeOffset? InsertedOn { get { throw null; } }
127138
public string MessageId { get { throw null; } }
139+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
128140
public string MessageText { get { throw null; } }
129141
}
130142
public partial class QueueAccessPolicy
@@ -246,10 +258,12 @@ internal QueueItem() { }
246258
public partial class QueueMessage
247259
{
248260
internal QueueMessage() { }
261+
public System.BinaryData Body { get { throw null; } }
249262
public long DequeueCount { get { throw null; } }
250263
public System.DateTimeOffset? ExpiresOn { get { throw null; } }
251264
public System.DateTimeOffset? InsertedOn { get { throw null; } }
252265
public string MessageId { get { throw null; } }
266+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
253267
public string MessageText { get { throw null; } }
254268
public System.DateTimeOffset? NextVisibleOn { get { throw null; } }
255269
public string PopReceipt { get { throw null; } }
@@ -296,9 +310,13 @@ public QueueSignedIdentifier() { }
296310
}
297311
public static partial class QueuesModelFactory
298312
{
313+
public static Azure.Storage.Queues.Models.PeekedMessage PeekedMessage(string messageId, System.BinaryData message, long dequeueCount, System.DateTimeOffset? insertedOn = default(System.DateTimeOffset?), System.DateTimeOffset? expiresOn = default(System.DateTimeOffset?)) { throw null; }
314+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
299315
public static Azure.Storage.Queues.Models.PeekedMessage PeekedMessage(string messageId, string messageText, long dequeueCount, System.DateTimeOffset? insertedOn = default(System.DateTimeOffset?), System.DateTimeOffset? expiresOn = default(System.DateTimeOffset?)) { throw null; }
300316
public static Azure.Storage.Queues.Models.QueueGeoReplication QueueGeoReplication(Azure.Storage.Queues.Models.QueueGeoReplicationStatus status, System.DateTimeOffset? lastSyncedOn = default(System.DateTimeOffset?)) { throw null; }
301317
public static Azure.Storage.Queues.Models.QueueItem QueueItem(string name, System.Collections.Generic.IDictionary<string, string> metadata = null) { throw null; }
318+
public static Azure.Storage.Queues.Models.QueueMessage QueueMessage(string messageId, string popReceipt, System.BinaryData body, long dequeueCount, System.DateTimeOffset? nextVisibleOn = default(System.DateTimeOffset?), System.DateTimeOffset? insertedOn = default(System.DateTimeOffset?), System.DateTimeOffset? expiresOn = default(System.DateTimeOffset?)) { throw null; }
319+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
302320
public static Azure.Storage.Queues.Models.QueueMessage QueueMessage(string messageId, string popReceipt, string messageText, long dequeueCount, System.DateTimeOffset? nextVisibleOn = default(System.DateTimeOffset?), System.DateTimeOffset? insertedOn = default(System.DateTimeOffset?), System.DateTimeOffset? expiresOn = default(System.DateTimeOffset?)) { throw null; }
303321
public static Azure.Storage.Queues.Models.QueueProperties QueueProperties(System.Collections.Generic.IDictionary<string, string> metadata, int approximateMessagesCount) { throw null; }
304322
public static Azure.Storage.Queues.Models.QueueServiceStatistics QueueServiceStatistics(Azure.Storage.Queues.Models.QueueGeoReplication geoReplication = null) { throw null; }

sdk/storage/Azure.Storage.Queues/samples/Sample01a_HelloWorld.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static void ReceiveMessages(string connectionString, string queueName)
8080
foreach (QueueMessage message in queue.ReceiveMessages(maxMessages: 10).Value)
8181
{
8282
// "Process" the message
83-
Console.WriteLine($"Message: {message.MessageText}");
83+
Console.WriteLine($"Message: {message.Body}");
8484

8585
// Let the service know we're finished with the message and
8686
// it can be safely deleted.
@@ -110,7 +110,7 @@ public static void PeekMesssages(string connectionString, string queueName)
110110
foreach (PeekedMessage message in queue.PeekMessages(maxMessages: 10).Value)
111111
{
112112
// Inspect the message
113-
Console.WriteLine($"Message: {message.MessageText}");
113+
Console.WriteLine($"Message: {message.Body}");
114114
}
115115
}
116116

@@ -142,7 +142,7 @@ public static void ReceiveAndUpdate(string connectionString, string queueName)
142142
UpdateReceipt receipt = queue.UpdateMessage(
143143
message.MessageId,
144144
message.PopReceipt,
145-
message.MessageText,
145+
message.Body,
146146
TimeSpan.FromSeconds(5));
147147

148148
// Keep track of the updated messages
@@ -158,7 +158,7 @@ public static void ReceiveAndUpdate(string connectionString, string queueName)
158158
foreach (QueueMessage message in messages)
159159
{
160160
// "Process" the message
161-
Console.WriteLine($"Message: {message.MessageText}");
161+
Console.WriteLine($"Message: {message.Body}");
162162

163163
// Tell the service we need a little more time to process the message
164164
queue.DeleteMessage(message.MessageId, message.PopReceipt);

sdk/storage/Azure.Storage.Queues/samples/Sample01b_HelloWorldAsync.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static async Task ReceiveMessagesAsync(string connectionString, string qu
7878
foreach (QueueMessage message in (await queue.ReceiveMessagesAsync(maxMessages: 10)).Value)
7979
{
8080
// "Process" the message
81-
Console.WriteLine($"Message: {message.MessageText}");
81+
Console.WriteLine($"Message: {message.Body}");
8282

8383
// Let the service know we're finished with the message and
8484
// it can be safely deleted.
@@ -107,7 +107,7 @@ public static async Task PeekMesssagesAsync(string connectionString, string queu
107107
foreach (PeekedMessage message in (await queue.PeekMessagesAsync(maxMessages: 10)).Value)
108108
{
109109
// Inspect the message
110-
Console.WriteLine($"Message: {message.MessageText}");
110+
Console.WriteLine($"Message: {message.Body}");
111111
}
112112
}
113113

@@ -140,7 +140,7 @@ public static async Task ReceiveAndUpdateAsync(string connectionString, string q
140140
UpdateReceipt receipt = await queue.UpdateMessageAsync(
141141
message.MessageId,
142142
message.PopReceipt,
143-
message.MessageText,
143+
message.Body,
144144
TimeSpan.FromSeconds(5));
145145

146146
// Keep track of the updated messages
@@ -156,7 +156,7 @@ public static async Task ReceiveAndUpdateAsync(string connectionString, string q
156156
foreach (QueueMessage message in messages)
157157
{
158158
// "Process" the message
159-
Console.WriteLine($"Message: {message.MessageText}");
159+
Console.WriteLine($"Message: {message.Body}");
160160

161161
// Tell the service we need a little more time to process the message
162162
await queue.DeleteMessageAsync(message.MessageId, message.PopReceipt);

sdk/storage/Azure.Storage.Queues/src/Azure.Storage.Queues.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
44
</PropertyGroup>
@@ -18,6 +18,7 @@
1818
</Description>
1919
</PropertyGroup>
2020
<ItemGroup>
21+
<PackageReference Include="System.Memory.Data"/>
2122
<PackageReference Include="System.Text.Json" />
2223
</ItemGroup>
2324
<ItemGroup>

0 commit comments

Comments
 (0)