1

After making my first function a few months back, I decided it needed to be renamed, so I deleted it and started over. And I've now spent my entire day regretting it :). I appreciate anyone who's willing to take the time to help me out.

Using VsCode, I deployed a js Azure function with a queue trigger. Testing the code in the portal works as expected. When I send a message to the queue, I can see the message enter the queue, and then it disappears shortly after. However, the function logs never show it received the message. The functions intended action also never takes place.

Here is the host.json file incase it's relevant:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.*, 4.0.0)"
  },
  "concurrency": {
    "dynamicConcurrencyEnabled": true,
    "snapshotPersistenceEnabled": true
  }
}

Here is the function.json file:

{
  "bindings": [
    {
      "name": "queueItem",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "tenantfunctionqueue",
      "connection": "Storage"
    }
  ]
}

Please let me know if additional information would be helpful.

I've tried using both connection strings and assigning the function the Storage Queue Data Contributor role. I tried each independently and concurrently.

More specifically, I edited the Configuration > ApplicationSettings > AzureWebJobsStorage value to be the connection string of the Storage account holding my queue. The Storage resource and the Function App are in the same Resource Group.

With the Azure role assignment approach, I also edited the AzureWebJobsStorage to have the name AzureWebJobsStorage__nameofstorageaccount and gave it the value nameofstorageaccount.

I've triple and quadruple checked things, so I feel like I must be missing something in the process. Is anyone aware of any less-documented gotchas? It feels important that my queue messages disappear immediately after being received? Any help would really be appreciated!

Also I've seen that a c# implementation requires a decorator to specify the connection string, but as far as I can tell there is no equivalent in js? Just the module.exports = async function (context, queueItem) {} function. So I'm assuming I'm not doing anything wrong there.

2 Answers 2

1

I have created a Model V3 Node js function in vs code and then tested it locally to see if its working, post that I deployed it to Portal and added the below connection string (Queue_ConnectionString) in Environment Variables (for you, it might be Configuration if you haven't restarted your machine to get new Azure portal view).

index.js-

module.exports  =  async  function (context, myQueueItem) {
context.log('JavaScript queue trigger function processed work item', myQueueItem);
context.log('dequeueCount =', context.bindingData.dequeueCount);
};

function.json-

{
"bindings": [
{
"name": "myQueueItem",
"type": "queueTrigger",
"direction": "in",
"queueName": "js-queue-items",
"connection": "Queue_ConnectionString"
}
]
}

local.settings-

{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "node",
"Queue_ConnectionString": "Your storage account connection string"
}
}

Take the connection string from Storage account

enter image description here

After deploying on Portal, I added Queue_ConnectionString in Environment Variables like below

enter image description here

Then Added the message in the queue like below

enter image description here

You can see in the above screenshot, Dequeue count is 0.

Output-

Now the Dequeue count is updated to 1, as the message has been removed from the queue after being consumed.

enter image description here

It feels important that my queue messages disappear immediately after being received?

Yes, the message will get dequeued, right after it's been consumed by your function, hence it will get disappear.

When I send a message to the queue, I can see the message enter the queue, and then it disappears shortly after. However, the function logs never show it received the message.

Pease make sure, your function is not both locally and in portal. If it running locally as well as in portal, then it might have been consumed by the local function.

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

1 Comment

Thank you so much for your answer! It's the most thorough explanation I've seen after searching stack overflow. Most of all it was so helpful to get confirmation I'm not going about things the wrong way. I'm going to add another answer to log what my exact issue was incase it helps someone else one day. Thanks again for taking the time!
0

I got it working! The issue was with my function.json

I had changed the "name" attributes value to "queueItem". Changing it back (and changin the parameter name in my function back) resolved my issue.

I'm leaving Ikhtesam Afrin's answer as the correct one because it is the most complete explanation I've found online so far.

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.