1
votes

I'm using an azure queue storage to get blob-paths for an Azure Function to access a blob on the same storage account. (It turns out I've more or less manually created a blob storage Azure Function).

I'm using the QueueClient class to get the messages from the queue and there are two methods: Azure Python Documentation

  1. receive_messages(**kwargs)
  2. peek_messages(max_messages=None, **kwargs)

I would like to be able to scale this function horizontally, so each time it's triggered (I've set it up as an HTTP function being triggered from an Azure Logic App) it grabs the FIRST message in the queue and only the first, and once retrieved deletes said message.

My problem is that peek does not make it invisible or return a pop_receipt for deletion later. And receive does not have a parameter for max_messages so that I can take one and only one message.

Does anyone have any knowledge of how to get around this roadblock?

2

2 Answers

1
votes

You can try receiving messages in a batch by passing messages_per_page argument to receive_messages. From this link:

        # Receive messages by batch
        messages = queue.receive_messages(messages_per_page=5)
        for msg_batch in messages.by_page():
            for msg in msg_batch:
                print(msg.content)
                queue.delete_message(msg)
0
votes

@Robert,

To fetch only one message from a queue you can use the code below:

pages = queue.receive_messages(visibility_timeout=30, messages_per_page=1).by_page()
page = next(pages)
msg = next(page)
print(msg)

The documentation of the receive_messages() is wrong.

Please see this for more information.