0

I am working on a function app (python v2 model) that puts a message into an Azure Queue.

  • When I run the function from the project, I get a successful response BUT the message does not actually show up in the queue.
  • When I run the function outside of my VS Code environment (Jupyter notebook), the message shows in the queue.

Below is a sample of the function:

import azure.functions as func
from azure.storage.queue import QueueServiceClient, QueueMessage
import logging
........
def add_message_to_queue(queue_name, connection_string, message):
    # Create a QueueServiceClient using the connection string
    queue_service_client = QueueServiceClient.from_connection_string(connection_string)

    # Get the queue client
    queue_client = queue_service_client.get_queue_client(queue_name)

    # Add the message to the queue
    queue_client.send_message(message)
    return queue_client.send_message(message)

    
    
def addTolog_queue(message):

    queue_name = 'xxxxxxx'
    connection_string = 'xxxxxxxxxxxx'

    return add_message_to_queue(queue_name, connection_string, message)


@app.route(route="xxxxx", auth_level=func.AuthLevel.FUNCTION)
def xxxxxx(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:

    .............
    print(addTolog_queue(log_payload))
    
    return func.HttpResponse(
            body=json.dumps({}),
            mimetype="application/json",
            status_code=200
        )


@app.queue_trigger(arg_name="azqueue", queue_name="xxxxxxx",
                               connection="xxxxxx_STORAGE") 
def queue_trigger(azqueue: func.QueueMessage):
    logging.info('Python Queue trigger processed a message: %s',
                azqueue.get_body().decode('utf-8'))
    
    que_payload = azqueue.get_body().decode('utf-8')
    print(que_payload)
    print("posting")
    post_log(que_payload)

The response from the function is the following (displayed from the print statement.)

{'id': '1f5fe7dd-6d69-45d1-9bf4-86e62a3e4249', 'inserted_on': datetime.datetime(2023, 12, 15, 6, 43, 51, tzinfo=datetime.timezone.utc), 'expires_on': datetime.datetime(2023, 12, 22, 6, 43, 51, tzinfo=datetime.timezone.utc), 'dequeue_count': None, 'content': xxxxxxxxxx, 'pop_receipt': 'AgAAAAMAAAAAAAAACVCVECIv2gE=', 'next_visible_on': datetime.datetime(2023, 12, 15, 6, 43, 51, tzinfo=datetime.timezone.utc)}

Has anyone ran into this before? Any ideas on how to fix it? I could not find single article where someone ran into the same issue.

UPDATE #1

Strangely enough, I created a brand new queue and the message successful enters the queue on the Azure portal. I still don't know why but this is concerning functionality. Something is compromising the other queues from fully ingesting the message.

UPDATE #2

Getting closer...

I noticed when I remove the Queue function, the problem goes away. When I re-add the problem starts again. The issue has something to with the fact that I'm adding a message to a queue in the same environment that is triggered off adding the message to the queue.

Related article, although increasing workers has not helped: Why is Azure httpTrigger waiting for queueTrigger to finish processing?

4
  • Can you confirm that which functions trigger you are using? Commented Dec 15, 2023 at 7:34
  • The function is using a HTTP trigger AND a queue trigger. I'm begging to think it's just not supported. Commented Dec 15, 2023 at 7:43
  • Can you try to run both triggers in the v2 function model? Commented Dec 15, 2023 at 8:01
  • Yes I am running them in the V2 model Commented Dec 15, 2023 at 8:05

2 Answers 2

1

I tried the below code and was able to see the message sent to the storage queue with HTTP and queue trigger functions in the v2 model.

Code :

import azure.functions as func
from azure.storage.queue import QueueServiceClient, QueueMessage
import logging
import json
import os

app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)

def add_message_to_queue(queue_name, connection_string, message):
    queue_service_client = QueueServiceClient.from_connection_string(connection_string)

    queue_client = queue_service_client.get_queue_client(queue_name)

    queue_client.send_message(message)
    return queue_client.send_message(message)

def addTolog_queue(message):
    queue_name = 'kamque'
    connection_string = os.environ['QueueStorageConnection']
    return add_message_to_queue(queue_name, connection_string, message)

@app.route(route="myfunction", auth_level=func.AuthLevel.FUNCTION)
def my_function(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
    log_payload = "Hi Kamali!" 
    print(addTolog_queue(log_payload))
    
    return func.HttpResponse(
            body=json.dumps({}),
            mimetype="application/json",
            status_code=200
        )

def post_log(data):
    pass

@app.queue_trigger(arg_name="azqueue", queue_name="kamque", connection="QueueStorageConnection") 
def queue_trigger(azqueue: func.QueueMessage):
    logging.info('Python Queue trigger processed a message: %s', azqueue.get_body().decode('utf-8'))
    
    que_payload = azqueue.get_body().decode('utf-8')
    print(que_payload)
    print("posting")
    post_log(que_payload)  

local.settings.json :

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
    "QueueStorageConnection": "<connec_string>"
  }
}

Output :

It runs successfully as below,

enter image description here

I got below with the above HTTP trigger output URL,

enter image description here

I got the below response in the output terminal,

enter image description here enter image description here

As mentioned in the above output message has reached MaxDequeueCount of 5. Moving message to queue 'kamque-poison'. I got the message in the kamque-poison as below,

enter image description here

Then, I send a message to the queue as below,

enter image description here

I got the message from the storage queue for the queue trigger function as below,

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the details. This was super helpful. I think I figured out the issue on my side. Very silly - the queue trigger automatically removes the record from the queue, so I kept checking the queue after it had already been removed. THANK YOU!
0

Very silly - the queue trigger automatically removes the record from the queue, so I kept checking the queue after it had already been removed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.