Reputation: 67
Creating a queue trigger function using serverless creates the function, but when a new message is added to the queue it doesn't trigger. A queue trigger function created from the portal using the same configuration (queue name, connection string) gets triggered when a new message is added to the queue.
serverless.yml
...
functions:
storageQueue:
handler: src/handlers/goodbye.sayGoodbye
events:
- queue: example-queue
name: myQueueItem
connection: STORAGE_CONNECTION_STRING
This is the json file generated for the queue trigger function from serverless. function.json
{
"disabled": false,
"bindings": [
{
"type": "queueTrigger",
"direction": "in",
"name": "myQueueItem",
"queueName": "example-queue",
"connection": "STORAGE_CONNECTION_STRING"
}
],
"entryPoint": "sayGoodbye",
"scriptFile": "../src/handlers/goodbye.js"
}
This is the json file generated for the function if its created from the portal. function.json
{
"bindings": [
{
"name": "myQueueItem",
"queueName": "example-queue",
"connection": "STORAGE_CONNECTION_STRING",
"direction": "in",
"type": "queueTrigger"
}
]
}
As you can see the bindings part is the same for both functions, but only the one created from the portal works.
Upvotes: 0
Views: 984
Reputation: 4778
Here is the workaround I did to create an Azure Serverless Function of JavaScript Stack - Azure Queue Storage Trigger in Visual Studio Code and it is triggering successfully after adding a message to the created Queue.
And the code is: function.json
{
"bindings": [
{
"name": "myQueueItem",
"type": "queueTrigger",
"direction": "in",
"queueName": "js-queue-items",
"connection": "storageaccountjbd99_STORAGE"
}
]
}
host.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
}
}
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "Azure Connection Storage string",
"FUNCTIONS_WORKER_RUNTIME": "node",
"storageaccountjbd99_STORAGE": "Azure Connection Storage string"
}
}
Here the AzureWebJobsStorage
and storageaccountjbd99_STORAGE
connection string values should be same if you're connecting to Azure Storage Account.
If the storage account is created in Azure, while creating the function it asks to select the Azure Storage account or use local storage account, here I selected the existing Azure Storage account so the connection value is the storage account name.
After that, I run the function and in Azure Storage Explorer, create the queue name called js-queue-items
and added the message in the Queue.
After adding the message, the function triggered its functionality and shown the output as you see in below:
Upvotes: 1