You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For code samples using the latest version 12.x client library version, see [Quickstart: Azure Queue Storage client library for .NET](storage-quickstart-queues-dotnet.md).
21
21
22
-
Related article: [Get started with Azure Queue Storage using .NET](storage-quickstart-queues-dotnet.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
22
+
## Create a Queue Storage client
23
23
24
24
The [`CloudQueueClient`](/dotnet/api/microsoft.azure.storage.queue.cloudqueueclient?view=azure-dotnet-legacy&preserve-view=true) class enables you to retrieve queues stored in Queue Storage. Here's one way to create the service client:
Related article: [Get started with Azure Queue Storage using .NET](storage-quickstart-queues-dotnet.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
38
-
39
37
This example shows how to create a queue:
40
38
41
39
```csharp
@@ -55,8 +53,6 @@ queue.CreateIfNotExists();
55
53
56
54
## Insert a message into a queue
57
55
58
-
Related article: [Get started with Azure Queue Storage using .NET](storage-quickstart-queues-dotnet.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
59
-
60
56
To insert a message into an existing queue, first create a new [`CloudQueueMessage`](/dotnet/api/microsoft.azure.storage.queue.cloudqueuemessage?view=azure-dotnet-legacy&preserve-view=true). Next, call the [`AddMessage`](/dotnet/api/microsoft.azure.storage.queue.cloudqueue.addmessage?view=azure-dotnet-legacy&preserve-view=true) method. A `CloudQueueMessage` can be created from either a string (in UTF-8 format) or a byte array. The following code example creates a queue (if it doesn't already exist) and inserts the message `Hello, World`:
61
57
62
58
```csharp
@@ -80,8 +76,6 @@ queue.AddMessage(message);
80
76
81
77
## Peek at the next message
82
78
83
-
Related article: [Get started with Azure Queue Storage using .NET](storage-quickstart-queues-dotnet.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
84
-
85
79
You can peek at the message in the front of a queue without removing it from the queue by calling the [`PeekMessage`](/dotnet/api/microsoft.azure.storage.queue.cloudqueue.peekmessage?view=azure-dotnet-legacy&preserve-view=true) method.
Related article: [Get started with Azure Queue Storage using .NET](storage-quickstart-queues-dotnet.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
108
-
109
101
```csharp
110
102
// Retrieve storage account from connection string.
Related article: [Get started with Azure Queue Storage using .NET](storage-quickstart-queues-dotnet.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
131
-
132
122
Your code dequeues a message from a queue in two steps. When you call [`GetMessage`](/dotnet/api/microsoft.azure.storage.queue.cloudqueue.getmessage?view=azure-dotnet-legacy&preserve-view=true), you get the next message in a queue. A message returned from `GetMessage` becomes invisible to any other code reading messages from this queue. By default, this message stays invisible for 30 seconds. To finish removing the message from the queue, you must also call [`DeleteMessage`](/dotnet/api/microsoft.azure.storage.queue.cloudqueue.deletemessage?view=azure-dotnet-legacy&preserve-view=true). This two-step process of removing a message assures that if your code fails to process a message due to hardware or software failure, another instance of your code can get the same message and try again. Your code calls `DeleteMessage` right after the message has been processed.
## Use the async-await pattern with common Queue Storage APIs
153
143
154
-
Related article: [Get started with Azure Queue Storage using .NET](storage-quickstart-queues-dotnet.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
Related article: [Get started with Azure Queue Storage using .NET](storage-quickstart-queues-dotnet.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
186
-
187
173
The following code example uses the [`GetMessages`](/dotnet/api/microsoft.azure.storage.queue.cloudqueue.getmessages?view=azure-dotnet-legacy&preserve-view=true) method to get 20 messages in one call. Then it processes each message using a `foreach` loop. It also sets the invisibility timeout to five minutes for each message. The timeout starts for all messages at the same time, so after five minutes have passed since the call to `GetMessages`, any messages that haven't been deleted will become visible again.
188
174
189
175
```csharp
@@ -206,8 +192,6 @@ foreach (CloudQueueMessage message in queue.GetMessages(20, TimeSpan.FromMinutes
206
192
207
193
## Get the queue length
208
194
209
-
Related article: [Get started with Azure Queue Storage using .NET](storage-quickstart-queues-dotnet.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
210
-
211
195
You can get an estimate of the number of messages in a queue. The [`FetchAttributes`](/dotnet/api/microsoft.azure.storage.queue.cloudqueue.fetchattributes?view=azure-dotnet-legacy&preserve-view=true) method returns queue attributes including the message count. The [`ApproximateMessageCount`](/dotnet/api/microsoft.azure.storage.queue.cloudqueue.approximatemessagecount?view=azure-dotnet-legacy&preserve-view=true) property returns the last value retrieved by the `FetchAttributes` method, without calling Queue Storage.
212
196
213
197
```csharp
@@ -233,8 +217,6 @@ Console.WriteLine("Number of messages in queue: " + cachedMessageCount);
233
217
234
218
## Delete a queue
235
219
236
-
Related article: [Get started with Azure Queue Storage using .NET](storage-quickstart-queues-dotnet.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
237
-
238
220
To delete a queue and all the messages contained in it, call the [`Delete`](/dotnet/api/microsoft.azure.storage.queue.cloudqueue.delete?view=azure-dotnet-legacy&preserve-view=true) method on the queue object.
For code samples using the latest version 12.x client library version, see [Quickstart: Azure Queue Storage client library for Python](storage-quickstart-queues-python.md).
21
21
22
-
Related article: [Get started with Azure Queue Storage using Python](storage-quickstart-queues-python.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2C)
Related article: [Get started with Azure Queue Storage using Python](storage-quickstart-queues-python.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
65
-
66
64
To insert a message into a queue, use the [`put_message`](/azure/developer/python/sdk/storage/azure-storage-queue/azure.storage.queue.queueservice.queueservice?view=storage-py-v2&preserve-view=true#put-message-queue-name--content--visibility-timeout-none--time-to-live-none--timeout-none-) method to create a new message and add it to the queue.
Related article: [Get started with Azure Queue Storage using Python](storage-quickstart-queues-python.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
77
-
78
74
You can peek at messages without removing them from the queue by calling the [`peek_messages`](/azure/developer/python/sdk/storage/azure-storage-queue/azure.storage.queue.queueservice.queueservice?view=storage-py-v2&preserve-view=true#peek-messages-queue-name--num-messages-none--timeout-none-) method. By default, this method peeks at a single message.
79
75
80
76
```python
@@ -86,8 +82,6 @@ for peeked_message in messages:
86
82
87
83
## Change the contents of a queued message
88
84
89
-
Related article: [Get started with Azure Queue Storage using Python](storage-quickstart-queues-python.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
90
-
91
85
The following code uses the [`update_message`](/azure/developer/python/sdk/storage/azure-storage-queue/azure.storage.queue.queueservice.queueservice?view=storage-py-v2&preserve-view=true#update-message-queue-name--message-id--pop-receipt--visibility-timeout--content-none--timeout-none-) method to update a message. The visibility timeout is set to 0, meaning the message appears immediately and the content is updated.
92
86
93
87
```python
@@ -100,8 +94,6 @@ for message in messages:
100
94
101
95
## Get the queue length
102
96
103
-
Related article: [Get started with Azure Queue Storage using Python](storage-quickstart-queues-python.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
104
-
105
97
The [`get_queue_metadata`](/azure/developer/python/sdk/storage/azure-storage-queue/azure.storage.queue.queueservice.queueservice?view=storage-py-v2&preserve-view=true#get-queue-metadata-queue-name--timeout-none-) method returns queue properties including `approximate_message_count`.
106
98
107
99
```python
@@ -114,8 +106,6 @@ The result is only approximate because messages can be added or removed after th
114
106
115
107
## Dequeue messages
116
108
117
-
Related article: [Get started with Azure Queue Storage using Python](storage-quickstart-queues-python.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
118
-
119
109
When you call [get_messages](/azure/developer/python/sdk/storage/azure-storage-queue/azure.storage.queue.queueservice.queueservice?view=storage-py-v2&preserve-view=true#get-messages-queue-name--num-messages-none--visibility-timeout-none--timeout-none-), you get the next message in the queue by default. A message returned from `get_messages` becomes invisible to any other code reading messages from this queue. By default, this message stays invisible for 30 seconds. To finish removing the message from the queue, you must also call [delete_message](/azure/developer/python/sdk/storage/azure-storage-queue/azure.storage.queue.queueservice.queueservice?view=storage-py-v2&preserve-view=true#delete-message-queue-name--message-id--pop-receipt--timeout-none-).
120
110
121
111
```python
@@ -140,8 +130,6 @@ for message in messages:
140
130
141
131
## Delete a queue
142
132
143
-
Related article: [Get started with Azure Queue Storage using Python](storage-quickstart-queues-python.md?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
144
-
145
133
To delete a queue and all the messages contained in it, call the [`delete_queue`](/azure/developer/python/sdk/storage/azure-storage-queue/azure.storage.queue.queueservice.queueservice?view=storage-py-v2&preserve-view=true#delete-queue-queue-name--fail-not-exist-false--timeout-none-) method.
For code samples using the latest version 12.x client library version, see [Quickstart: Azure Queue Storage client library for Java](storage-quickstart-queues-java.md).
21
21
22
-
Related article: [Get started with Azure Queue Storage using Java](storage-quickstart-queues-java.md?tabs=powershell%2Cpasswordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
22
+
## Create a queue
23
23
24
24
Add the following `import` directives:
25
25
@@ -58,8 +58,6 @@ catch (Exception e)
58
58
59
59
## Add a message to a queue
60
60
61
-
Related article: [Get started with Azure Queue Storage using Java](storage-quickstart-queues-java.md?tabs=powershell%2Cpasswordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
62
-
63
61
To insert a message into an existing queue, first create a new `CloudQueueMessage`. Next, call the `addMessage` method. A `CloudQueueMessage` can be created from either a string (in UTF-8 format) or a byte array. The following code example creates a queue (if it doesn't exist) and inserts the message `Hello, World`.
64
62
65
63
```java
@@ -91,8 +89,6 @@ catch (Exception e)
91
89
92
90
## Peek at the next message
93
91
94
-
Related article: [Get started with Azure Queue Storage using Java](storage-quickstart-queues-java.md?tabs=powershell%2Cpasswordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
95
-
96
92
You can peek at the message in the front of a queue without removing it from the queue by calling `peekMessage`.
97
93
98
94
```java
@@ -126,8 +122,6 @@ catch (Exception e)
126
122
127
123
## Change the contents of a queued message
128
124
129
-
Related article: [Get started with Azure Queue Storage using Java](storage-quickstart-queues-java.md?tabs=powershell%2Cpasswordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
130
-
131
125
The following code sample searches through the queue of messages, locates the first message content that matches `Hello, world`, modifies the message content, and exits.
132
126
133
127
```java
@@ -210,8 +204,6 @@ catch (Exception e)
210
204
211
205
## Get the queue length
212
206
213
-
Related article: [Get started with Azure Queue Storage using Java](storage-quickstart-queues-java.md?tabs=powershell%2Cpasswordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
214
-
215
207
The `downloadAttributes` method retrieves several values including the number of messages currently in a queue. The count is only approximate because messages can be added or removed after your request. The `getApproximateMessageCount` method returns the last value retrieved by the call to `downloadAttributes`, without calling Queue Storage.
216
208
217
209
```java
@@ -245,8 +237,6 @@ catch (Exception e)
245
237
246
238
## Dequeue the next message
247
239
248
-
Related article: [Get started with Azure Queue Storage using Java](storage-quickstart-queues-java.md?tabs=powershell%2Cpasswordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
249
-
250
240
Your code dequeues a message from a queue in two steps. When you call `retrieveMessage`, you get the next message in a queue. A message returned from `retrieveMessage` becomes invisible to any other code reading messages from this queue. By default, this message stays invisible for 30 seconds. To finish removing the message from the queue, you must also call `deleteMessage`. If your code fails to process a message, this two-step process ensures that you can get the same message and try again. Your code calls `deleteMessage` right after the message has been processed.
251
241
252
242
```java
@@ -280,8 +270,6 @@ catch (Exception e)
280
270
281
271
## Additional options for dequeuing messages
282
272
283
-
Related article: [Get started with Azure Queue Storage using Java](storage-quickstart-queues-java.md?tabs=powershell%2Cpasswordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
284
-
285
273
The following code example uses the `retrieveMessages` method to get 20 messages in one call. Then it processes each message using a `for` loop. It also sets the invisibility timeout to five minutes (300 seconds) for each message. The timeout starts for all messages at the same time. When five minutes have passed since the call to `retrieveMessages`, any messages not deleted becomes visible again.
286
274
287
275
```java
@@ -313,8 +301,6 @@ catch (Exception e)
313
301
314
302
## List the queues
315
303
316
-
Related article: [Get started with Azure Queue Storage using Java](storage-quickstart-queues-java.md?tabs=powershell%2Cpasswordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
317
-
318
304
To obtain a list of the current queues, call the `CloudQueueClient.listQueues()` method, which returns a collection of `CloudQueue` objects.
319
305
320
306
```java
@@ -344,8 +330,6 @@ catch (Exception e)
344
330
345
331
## Delete a queue
346
332
347
-
Related article: [Get started with Azure Queue Storage using Java](storage-quickstart-queues-java.md?tabs=powershell%2Cpasswordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
348
-
349
333
To delete a queue and all the messages contained in it, call the `deleteIfExists` method on the `CloudQueue` object.
0 commit comments