Azure Function Queue Trigger V2 not reading the message

Pedro Junqueira 40 Reputation points
2023-09-25T20:56:30.9166667+00:00

I am trying to read a message from a queue storage.

I am following exactly the tutorial code and running locally using azurite (tested also with a storage).

The the strange thing is that when a new message arrive at the queue the function gets triggered and then moved to poison queue but nothing happens in between.

The logs do not log, therefore I cannot do anything with the message.

@app.queue_trigger(arg_name="azqueue", queue_name="hyper-tyre-to-process",
                               connection="AzureStorageAccount") 
def queue_trigger(azqueue: func.QueueMessage):
   
   logging.info('Python queue trigger function processed a queue item: %s',
                 azqueue.get_body().decode('utf-8'))


User's image

It works but but really does not do the most important thing. Read the message.

What I am doing wrong?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
Azure Queue Storage
Azure Queue Storage
An Azure service that provides messaging queues in the cloud.
114 questions
{count} votes

Accepted answer
  1. navba-MSFT 27,540 Reputation points Microsoft Employee Moderator
    2023-09-27T10:35:57.96+00:00

    @Pedro Junqueira I'm glad to see you were able to resolve your issue.

    Thanks for posting your solution so that others experiencing the same thing can easily reference this. Since the Microsoft Q&A community has a policy that the question author cannot accept their own answer, they can only accept answers by others, I'll repost your solution in case you'd like to Accept the answer.

    Issue:
    You have a Python QueueTrigger Function app which is not able to read the new message in the queue and you are getting the error Message has reached MaxDequeueCount of 5. Moving message to queue.

    Resolution:

    The above error message is completely misleading and has nothing to do with the encoding issue. The same has been already been reported to MSFT as a bug.

    You got the right code from this stackoverflow post.

    Here is the code that you have used and it is working when sending the message to be then able to get the message using function trigger.

    from azure.storage.queue import (
            QueueClient,
            BinaryBase64EncodePolicy,
            BinaryBase64DecodePolicy
    )
    queue_client = QueueClient.from_connection_string(
        connection_string,
        queue_name
        )
    
    # Setup Base64 encoding and decoding functions
    queue_client.message_encode_policy = BinaryBase64EncodePolicy()
    queue_client.message_decode_policy = BinaryBase64DecodePolicy()
    
    for i in range(10):
    
        print(f'Sending message {i}')
        message = {'id': i, 'message' :'Hello World'}
        message_string = json.dumps(message)
        message_bytes =  message_string.encode('utf-8')
        queue_client.send_message(
            queue_client.message_encode_policy.encode(content=message_bytes)
            )
    
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.