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
This guide shows you how to perform common scenarios using the Azure Queue storage service. The samples are written in Python and use the [Microsoft Azure Storage SDK for Python]. The scenarios covered include **inserting**, **peeking**, **getting**, and **deleting** queue messages, as well as **creating and deleting queues**. For more information on queues, refer to the [Next Steps] section.
22
+
23
+
This guide shows you how to perform common scenarios using the Azure Queue storage service. The samples are written in Python and use the [Microsoft Azure Storage SDK for Python]. The scenarios covered include inserting, peeking, getting, and deleting queue messages, as well as creating and deleting queues. For more information on queues, refer to the [Next steps](#next-steps) section.
## Download and Install Azure Storage SDK for Python
29
+
## Download and install Azure Storage SDK for Python
28
30
29
-
The [Azure Storage SDK for Python](https://github.com/azure/azure-storage-python) requires Python 2.7, 3.3, 3.4, 3.5, or 3.6.
31
+
The [Azure Storage SDK for Python](https://github.com/azure/azure-storage-python) requires Python version 2.7, 3.3, or later.
30
32
31
33
### Install via PyPi
32
34
@@ -47,52 +49,51 @@ To view and run a sample application that shows how to use Python with Azure Que
47
49
48
50
To run the sample application, make sure you have installed both the `azure-storage-queue` and `azure-storage-common` packages.
49
51
50
-
## How To: Create a Queue
52
+
## Create a queue
51
53
52
-
The **QueueService** object lets you work with queues. The following code creates a **QueueService** object. Add the following near the top of any Python file in which you wish to programmatically access Azure Storage:
54
+
The [QueueService](/python/api/azure-storage-queue/azure.storage.queue.queueservice.queueservice) object lets you work with queues. The following code creates a `QueueService` object. Add the following near the top of any Python file in which you wish to programmatically access Azure Storage:
53
55
54
56
```python
55
57
from azure.storage.queue import QueueService
56
58
```
57
59
58
-
The following code creates a **QueueService** object using the storage account name and account key. Replace 'myaccount' and 'mykey' with your account name and key.
60
+
The following code creates a `QueueService` object using the storage account name and account key. Replace *myaccount* and *mykey* with your account name and key.
To insert a message into a queue, use the **put\_message** method to
68
-
create a new message and add it to the queue.
68
+
## Insert a message into a queue
69
+
70
+
To insert a message into a queue, use the [put_message](/python/api/azure-storage-queue/azure.storage.queue.queueservice.queueservice#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.
You can peek at the message in the front of a queue without removing it
76
-
from the queue by calling the **peek\_messages** method. By default,
77
-
**peek\_messages** peeks at a single message.
76
+
Azure queue messages are stored as text. If you want to store binary data, setup Base64 encoding and decoding functions on the queue service object before putting a message in the queue.
77
+
78
+
```python
79
+
# setup queue Base64 encoding and decoding functions
You can peek at the message in the front of a queue without removing it from the queue by calling the [peek_messages](/python/api/azure-storage-queue/azure.storage.queue.queueservice.queueservice#peek-messages-queue-name--num-messages-none--timeout-none-) method. By default, `peek_messages` peeks at a single message.
Your code removes a message from a queue in two steps. When you call
87
-
**get\_messages**, you get the next message in a queue by default. A
88
-
message returned from **get\_messages** becomes invisible to any other
89
-
code reading messages from this queue. By default, this message stays
90
-
invisible for 30 seconds. To finish removing the message from the queue,
91
-
you must also call **delete\_message**. This two-step process of removing
92
-
a message assures that when your code fails to process a message due to
93
-
hardware or software failure, another instance of your code can get the
94
-
same message and try again. Your code calls **delete\_message** right
95
-
after the message has been processed.
94
+
## Dequeue messages
95
+
96
+
Your code removes a message from a queue in two steps. When you call [get_messages](/python/api/azure-storage-queue/azure.storage.queue.queueservice.queueservice#get-messages-queue-name--num-messages-none--visibility-timeout-none--timeout-none-), you get the next message in a 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](/python/api/azure-storage-queue/azure.storage.queue.queueservice.queueservice#delete-message-queue-name--message-id--pop-receipt--timeout-none-). This two-step process of removing a message assures that when 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 `delete_message` right after the message has been processed.
There are two ways you can customize message retrieval from a queue.
105
-
First, you can get a batch of messages (up to 32). Second, you can set a
106
-
longer or shorter invisibility timeout, allowing your code more or less
107
-
time to fully process each message. The following code example uses the
108
-
**get\_messages** method to get 16 messages in one call. Then it processes
109
-
each message using a for loop. It also sets the invisibility timeout to
110
-
five minutes for each message.
105
+
There are two ways you can customize message retrieval from a queue. First, you can get a batch of messages (up to 32). Second, you can set a longer or shorter invisibility timeout, allowing your code more or less time to fully process each message. The following code example uses the `get_messages` method to get 16 messages in one call. Then it processes each message using a for loop. It also sets the invisibility timeout to five minutes for each message.
## How To: Change the Contents of a Queued Message
121
-
You can change the contents of a message in-place in the queue. If the
122
-
message represents a work task, you could use this feature to update the
123
-
status of the work task. The code below uses the **update\_message**
124
-
method to update a message. The visibility timeout is set to 0, meaning the
125
-
message appears immediately and the content is updated.
115
+
## Change the contents of a queued message
116
+
117
+
You can change the contents of a message in-place in the queue. If the message represents a work task, you could use this feature to update the status of the work task. The code below uses the [update_message](/python/api/azure-storage-queue/azure.storage.queue.queueservice.queueservice#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.
'taskqueue', message.id, message.pop_receipt, 0, u'Hello World Again')
132
124
```
133
125
134
-
## How To: Get the Queue Length
135
-
You can get an estimate of the number of messages in a queue. The
136
-
**get\_queue\_metadata** method asks the queue service to return metadata
137
-
about the queue, and the **approximate_message_count**. The result is only
138
-
approximate because messages can be added or removed after the
139
-
queue service responds to your request.
126
+
## Get the queue length
127
+
128
+
You can get an estimate of the number of messages in a queue. The [get_queue_metadata](/python/api/azure-storage-queue/azure.storage.queue.queueservice.queueservice#get-queue-metadata-queue-name--timeout-none-) method asks the queue service to return metadata about the queue, and the `approximate_message_count`. The result is only approximate because messages can be added or removed after the queue service responds to your request.
To delete a queue and all the messages contained in it, call the
148
-
**delete\_queue** method.
135
+
## Delete a queue
136
+
137
+
To delete a queue and all the messages contained in it, call the [delete_queue](/python/api/azure-storage-queue/azure.storage.queue.queueservice.queueservice#delete-queue-queue-name--fail-not-exist-false--timeout-none-) method.
149
138
150
139
```python
151
140
queue_service.delete_queue('taskqueue')
152
141
```
153
142
154
-
## Next Steps
155
-
Now that you've learned the basics of Queue storage, follow these links
156
-
to learn more.
143
+
## Next steps
144
+
145
+
Now that you've learned the basics of queue storage, follow these links to learn more.
157
146
147
+
*[Azure Queues Python API reference](/python/api/azure-storage-queue)
Copy file name to clipboardExpand all lines: includes/storage-queue-concepts-include.md
+4-7Lines changed: 4 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,16 +5,13 @@ ms.topic: include
5
5
ms.date: 10/26/2018
6
6
ms.author: tamram
7
7
---
8
-
## What is Queue Storage?
9
-
Azure Queue storage is a service for storing large numbers of messages that can be accessed from anywhere in the world via authenticated calls using HTTP or HTTPS. A single queue message can be up to 64 KB in size, and a queue can contain millions of messages, up to the total capacity limit of a storage account.
8
+
## What is queue storage?
10
9
11
-
Common uses of Queue storage include:
10
+
Azure Queue storage is a service for storing large numbers of messages that can be accessed from anywhere in the world via authenticated calls using HTTP or HTTPS. A single queue message can be up to 64 KB in size, and a queue can contain millions of messages, up to the total capacity limit of a storage account. Queue storage is often used to create a backlog of work to process asynchronously.
12
11
13
-
* Creating a backlog of work to process asynchronously
14
-
* Passing messages from an Azure web role to an Azure worker role
12
+
## Queue service concepts
15
13
16
-
## Queue Service Concepts
17
-
The Queue service contains the following components:
14
+
The Azure Queue service contains the following components:
0 commit comments