Skip to content

Commit 3e61e11

Browse files
authored
[Storage] Queues one message receive (#15180)
* Prepare Storage for release * pr feedback. * PR feedback. * pr feedback. * make open write work with using. * move recordings to right place * pr feedback. * receive one message. * peek one message * api * remove redundant scope. * pr feedback.
1 parent 28a6bc6 commit 3e61e11

21 files changed

+2033
-3
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ public QueueClient(System.Uri queueUri, Azure.Storage.StorageSharedKeyCredential
3232
public virtual System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IEnumerable<Azure.Storage.Queues.Models.QueueSignedIdentifier>>> GetAccessPolicyAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
3333
public virtual Azure.Response<Azure.Storage.Queues.Models.QueueProperties> GetProperties(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
3434
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Queues.Models.QueueProperties>> GetPropertiesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
35+
public virtual Azure.Response<Azure.Storage.Queues.Models.PeekedMessage> PeekMessage(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
36+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Queues.Models.PeekedMessage>> PeekMessageAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
3537
public virtual Azure.Response<Azure.Storage.Queues.Models.PeekedMessage[]> PeekMessages(int? maxMessages = default(int?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
3638
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Queues.Models.PeekedMessage[]>> PeekMessagesAsync(int? maxMessages = default(int?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
39+
public virtual Azure.Response<Azure.Storage.Queues.Models.QueueMessage> ReceiveMessage(System.TimeSpan? visibilityTimeout = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
40+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Queues.Models.QueueMessage>> ReceiveMessageAsync(System.TimeSpan? visibilityTimeout = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
3741
public virtual Azure.Response<Azure.Storage.Queues.Models.QueueMessage[]> ReceiveMessages() { throw null; }
3842
public virtual Azure.Response<Azure.Storage.Queues.Models.QueueMessage[]> ReceiveMessages(int? maxMessages = default(int?), System.TimeSpan? visibilityTimeout = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
3943
public virtual Azure.Response<Azure.Storage.Queues.Models.QueueMessage[]> ReceiveMessages(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }

sdk/storage/Azure.Storage.Queues/src/QueueClient.cs

Lines changed: 171 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,7 @@ public virtual Response<QueueMessage[]> ReceiveMessages(
17211721
ReceiveMessagesInternal(
17221722
maxMessages,
17231723
visibilityTimeout,
1724+
$"{nameof(QueueClient)}.{nameof(ReceiveMessages)}",
17241725
false, // async
17251726
cancellationToken)
17261727
.EnsureCompleted();
@@ -1752,6 +1753,7 @@ public virtual async Task<Response<QueueMessage[]>> ReceiveMessagesAsync(
17521753
await ReceiveMessagesInternal(
17531754
maxMessages,
17541755
visibilityTimeout,
1756+
$"{nameof(QueueClient)}.{nameof(ReceiveMessages)}",
17551757
true, // async
17561758
cancellationToken)
17571759
.ConfigureAwait(false);
@@ -1770,6 +1772,9 @@ await ReceiveMessagesInternal(
17701772
/// <param name="visibilityTimeout">
17711773
/// Optional. Specifies the new visibility timeout value, in seconds, relative to server time. The default value is 30 seconds.
17721774
/// </param>
1775+
/// <param name="operationName">
1776+
/// Operation name for diagnostic logging.
1777+
/// </param>
17731778
/// <param name="async">
17741779
/// Whether to invoke the operation asynchronously.
17751780
/// </param>
@@ -1782,6 +1787,7 @@ await ReceiveMessagesInternal(
17821787
private async Task<Response<QueueMessage[]>> ReceiveMessagesInternal(
17831788
int? maxMessages,
17841789
TimeSpan? visibilityTimeout,
1790+
string operationName,
17851791
bool async,
17861792
CancellationToken cancellationToken)
17871793
{
@@ -1803,7 +1809,7 @@ private async Task<Response<QueueMessage[]>> ReceiveMessagesInternal(
18031809
numberOfMessages: maxMessages,
18041810
visibilitytimeout: (int?)visibilityTimeout?.TotalSeconds,
18051811
async: async,
1806-
operationName: $"{nameof(QueueClient)}.{nameof(ReceiveMessages)}",
1812+
operationName: operationName,
18071813
cancellationToken: cancellationToken)
18081814
.ConfigureAwait(false);
18091815

@@ -1835,8 +1841,165 @@ private async Task<Response<QueueMessage[]>> ReceiveMessagesInternal(
18351841
}
18361842
}
18371843
}
1844+
18381845
#endregion ReceiveMessages
18391846

1847+
#region ReceiveMessage
1848+
1849+
/// <summary>
1850+
/// Receives one message from the front of the queue.
1851+
///
1852+
/// For more information, see
1853+
/// <see href="https://docs.microsoft.com/rest/api/storageservices/get-messages">
1854+
/// Get Messages</see>.
1855+
/// </summary>
1856+
/// <param name="visibilityTimeout">
1857+
/// Optional. Specifies the new visibility timeout value, in seconds, relative to server time. The default value is 30 seconds.
1858+
/// </param>
1859+
/// <param name="cancellationToken">
1860+
/// Optional <see cref="CancellationToken"/>
1861+
/// </param>
1862+
/// <returns>
1863+
/// <see cref="Response{T}"/> where T is a <see cref="QueueMessage"/>
1864+
/// </returns>
1865+
public virtual Response<QueueMessage> ReceiveMessage(
1866+
TimeSpan? visibilityTimeout = default,
1867+
CancellationToken cancellationToken = default) =>
1868+
ReceiveMessageInternal(
1869+
visibilityTimeout,
1870+
false, // async
1871+
cancellationToken)
1872+
.EnsureCompleted();
1873+
1874+
/// <summary>
1875+
/// Retrieves one message from the front of the queue.
1876+
///
1877+
/// For more information, see
1878+
/// <see href="https://docs.microsoft.com/rest/api/storageservices/get-messages">
1879+
/// Get Messages</see>.
1880+
/// </summary>
1881+
/// <param name="visibilityTimeout">
1882+
/// Optional. Specifies the new visibility timeout value, in seconds, relative to server time. The default value is 30 seconds.
1883+
/// </param>
1884+
/// <param name="cancellationToken">
1885+
/// Optional <see cref="CancellationToken"/>
1886+
/// </param>
1887+
/// <returns>
1888+
/// <see cref="Response{T}"/> where T is a <see cref="QueueMessage"/>
1889+
/// </returns>
1890+
public virtual async Task<Response<QueueMessage>> ReceiveMessageAsync(
1891+
TimeSpan? visibilityTimeout = default,
1892+
CancellationToken cancellationToken = default) =>
1893+
await ReceiveMessageInternal(
1894+
visibilityTimeout,
1895+
true, // async
1896+
cancellationToken)
1897+
.ConfigureAwait(false);
1898+
1899+
/// <summary>
1900+
/// Retrieves one message from the front of the queue.
1901+
///
1902+
/// For more information, see
1903+
/// <see href="https://docs.microsoft.com/rest/api/storageservices/get-messages">
1904+
/// Get Messages</see>.
1905+
/// </summary>
1906+
/// <param name="visibilityTimeout">
1907+
/// Optional. Specifies the new visibility timeout value, in seconds, relative to server time. The default value is 30 seconds.
1908+
/// </param>
1909+
/// <param name="async">
1910+
/// Whether to invoke the operation asynchronously.
1911+
/// </param>
1912+
/// <param name="cancellationToken">
1913+
/// Optional <see cref="CancellationToken"/>
1914+
/// </param>
1915+
/// <returns>
1916+
/// <see cref="Response{T}"/> where T is a <see cref="QueueMessage"/>
1917+
/// </returns>
1918+
private async Task<Response<QueueMessage>> ReceiveMessageInternal(
1919+
TimeSpan? visibilityTimeout,
1920+
bool async,
1921+
CancellationToken cancellationToken)
1922+
{
1923+
var response = await ReceiveMessagesInternal(
1924+
1,
1925+
visibilityTimeout,
1926+
$"{nameof(QueueClient)}.{nameof(ReceiveMessage)}",
1927+
async,
1928+
cancellationToken).ConfigureAwait(false);
1929+
var queueMessage = response.Value.FirstOrDefault();
1930+
var rawResponse = response.GetRawResponse();
1931+
return Response.FromValue(queueMessage, rawResponse);
1932+
}
1933+
#endregion ReceiveMessage
1934+
1935+
#region PeekMessage
1936+
/// <summary>
1937+
/// Retrieves one message from the front of the queue but does not alter the visibility of the message.
1938+
///
1939+
/// For more information, see
1940+
/// <see href="https://docs.microsoft.com/rest/api/storageservices/peek-messages">
1941+
/// Peek Messages</see>.
1942+
/// </summary>
1943+
/// <param name="cancellationToken">
1944+
/// Optional <see cref="CancellationToken"/>
1945+
/// </param>
1946+
/// <returns>
1947+
/// <see cref="Response{T}"/> where T is a <see cref="PeekedMessage"/>
1948+
/// </returns>
1949+
public virtual Response<PeekedMessage> PeekMessage(
1950+
CancellationToken cancellationToken = default) =>
1951+
PeekMessageInternal(
1952+
false, // async
1953+
cancellationToken)
1954+
.EnsureCompleted();
1955+
1956+
/// <summary>
1957+
/// Retrieves one message from the front of the queue but does not alter the visibility of the message.
1958+
///
1959+
/// For more information, see
1960+
/// <see href="https://docs.microsoft.com/rest/api/storageservices/peek-messages">
1961+
/// Peek Messages</see>.
1962+
/// </summary>
1963+
/// <param name="cancellationToken">
1964+
/// Optional <see cref="CancellationToken"/>
1965+
/// </param>
1966+
/// <returns>
1967+
/// <see cref="Response{T}"/> where T is a <see cref="PeekedMessage"/>
1968+
/// </returns>
1969+
public virtual async Task<Response<PeekedMessage>> PeekMessageAsync(
1970+
CancellationToken cancellationToken = default) =>
1971+
await PeekMessageInternal(
1972+
true, // async
1973+
cancellationToken)
1974+
.ConfigureAwait(false);
1975+
1976+
/// <summary>
1977+
/// Retrieves one message from the front of the queue but does not alter the visibility of the message.
1978+
///
1979+
/// For more information, see
1980+
/// <see href="https://docs.microsoft.com/rest/api/storageservices/peek-messages">
1981+
/// Peek Messages</see>.
1982+
/// </summary>
1983+
/// <param name="async">
1984+
/// Whether to invoke the operation asynchronously.
1985+
/// </param>
1986+
/// <param name="cancellationToken">
1987+
/// Optional <see cref="CancellationToken"/>
1988+
/// </param>
1989+
/// <returns>
1990+
/// <see cref="Response{T}"/> where T is a <see cref="PeekedMessage"/>
1991+
/// </returns>
1992+
private async Task<Response<PeekedMessage>> PeekMessageInternal(
1993+
bool async,
1994+
CancellationToken cancellationToken)
1995+
{
1996+
var response = await PeekMessagesInternal(1, $"{nameof(QueueClient)}.{nameof(PeekMessage)}", async, cancellationToken).ConfigureAwait(false);
1997+
var message = response.Value.FirstOrDefault();
1998+
var rawResonse = response.GetRawResponse();
1999+
return Response.FromValue(message, rawResonse);
2000+
}
2001+
#endregion PeekMessage
2002+
18402003
#region PeekMessages
18412004
/// <summary>
18422005
/// Retrieves one or more messages from the front of the queue but does not alter the visibility of the message.
@@ -1860,6 +2023,7 @@ public virtual Response<PeekedMessage[]> PeekMessages(
18602023
CancellationToken cancellationToken = default) =>
18612024
PeekMessagesInternal(
18622025
maxMessages,
2026+
$"{nameof(QueueClient)}.{nameof(PeekMessages)}",
18632027
false, // async
18642028
cancellationToken)
18652029
.EnsureCompleted();
@@ -1886,6 +2050,7 @@ public virtual async Task<Response<PeekedMessage[]>> PeekMessagesAsync(
18862050
CancellationToken cancellationToken = default) =>
18872051
await PeekMessagesInternal(
18882052
maxMessages,
2053+
$"{nameof(QueueClient)}.{nameof(PeekMessages)}",
18892054
true, // async
18902055
cancellationToken)
18912056
.ConfigureAwait(false);
@@ -1901,6 +2066,9 @@ await PeekMessagesInternal(
19012066
/// Optional. A nonzero integer value that specifies the number of messages to peek from the queue, up to a maximum of 32.
19022067
/// By default, a single message is peeked from the queue with this operation.
19032068
/// </param>
2069+
/// <param name="operationName">
2070+
/// Operation name for diagnostic logging.
2071+
/// </param>
19042072
/// <param name="async">
19052073
/// Whether to invoke the operation asynchronously.
19062074
/// </param>
@@ -1912,6 +2080,7 @@ await PeekMessagesInternal(
19122080
/// </returns>
19132081
private async Task<Response<PeekedMessage[]>> PeekMessagesInternal(
19142082
int? maxMessages,
2083+
string operationName,
19152084
bool async,
19162085
CancellationToken cancellationToken)
19172086
{
@@ -1931,7 +2100,7 @@ private async Task<Response<PeekedMessage[]>> PeekMessagesInternal(
19312100
version: Version.ToVersionString(),
19322101
numberOfMessages: maxMessages,
19332102
async: async,
1934-
operationName: $"{nameof(QueueClient)}.{nameof(PeekMessages)}",
2103+
operationName: operationName,
19352104
cancellationToken: cancellationToken)
19362105
.ConfigureAwait(false);
19372106

0 commit comments

Comments
 (0)