Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more docstring context and sample code for receive_messages() #13789

Merged
merged 5 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,17 @@ def receive_messages(self, **kwargs):
messages to retrieve from the queue, up to a maximum of 32. If
fewer are visible, the visible messages are returned. By default,
a single message is retrieved from the queue with this operation.
`by_page()` can be used to provide a page iterator on the AsyncItemPaged if messages_per_page is set.
`next()` can be used to get the next page.
.. admonition:: Example:

.. literalinclude:: ../samples/queue_samples_message.py
:start-after: [START receive_messages_listing]
:end-before: [END receive_messages_listing]
:language: python
:dedent: 12
:caption: List pages and corresponding messages from the queue.

:keyword int visibility_timeout:
If not specified, the default value is 0. Specifies the
new visibility timeout value, in seconds, relative to server time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ def receive_messages(self, **kwargs):
messages to retrieve from the queue, up to a maximum of 32. If
fewer are visible, the visible messages are returned. By default,
a single message is retrieved from the queue with this operation.
`by_page()` can be used to provide a page iterator on the AsyncItemPaged if messages_per_page is set.
`next()` can be used to get the next page.
:keyword int visibility_timeout:
If not specified, the default value is 0. Specifies the
new visibility timeout value, in seconds, relative to server time.
Expand Down
40 changes: 37 additions & 3 deletions sdk/storage/azure-storage-queue/samples/queue_samples_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,47 @@ def send_and_receive_messages(self):
# Delete the queue
queue.delete_queue()

def delete_and_clear_messages(self):
def list_message_pages(self):
# Instantiate a queue client
from azure.storage.queue import QueueClient
queue = QueueClient.from_connection_string(self.connection_string, "myqueue4")

# Create the queue
queue.create_queue()

try:
queue.send_message(u"message1")
queue.send_message(u"message2")
queue.send_message(u"message3")
queue.send_message(u"message4")
queue.send_message(u"message5")
queue.send_message(u"message6")

# [START receive_messages_listing]
# Store two messages in each page
message_batches = queue.receive_messages(messages_per_page=2).by_page()

# Iterate through the page lists
print(list(next(message_batches)))
print(list(next(message_batches)))

# There are two iterations in the last page as well.
last_page = next(message_batches)
for message in last_page:
print(message)
# [END receive_messages_listing]

finally:
queue.delete_queue()

def delete_and_clear_messages(self):
# Instantiate a queue client
from azure.storage.queue import QueueClient
queue = QueueClient.from_connection_string(self.connection_string, "myqueue5")

# Create the queue
queue.create_queue()

try:
# Send messages
queue.send_message(u"message1")
Expand Down Expand Up @@ -181,7 +214,7 @@ def delete_and_clear_messages(self):
def peek_messages(self):
# Instantiate a queue client
from azure.storage.queue import QueueClient
queue = QueueClient.from_connection_string(self.connection_string, "myqueue5")
queue = QueueClient.from_connection_string(self.connection_string, "myqueue6")

# Create the queue
queue.create_queue()
Expand Down Expand Up @@ -213,7 +246,7 @@ def peek_messages(self):
def update_message(self):
# Instantiate a queue client
from azure.storage.queue import QueueClient
queue = QueueClient.from_connection_string(self.connection_string, "myqueue6")
queue = QueueClient.from_connection_string(self.connection_string, "myqueue7")

# Create the queue
queue.create_queue()
Expand Down Expand Up @@ -245,6 +278,7 @@ def update_message(self):
sample.set_access_policy()
sample.queue_metadata()
sample.send_and_receive_messages()
sample.list_message_pages()
sample.delete_and_clear_messages()
sample.peek_messages()
sample.update_message()