Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

v2 Azure Function with Service Bus trigger not firing

I am using Azure Functions V2 with a Service Bus trigger using 1.0.23 of the C# Functions SDK. I'm using the following approach to get secrets from KeyVault and use them within the settings of the triggers: How to map Azure Functions secrets from Key Vault automatically

The function, especially when it has done nothing for a while, doesn't fire when there are messages on the subscription. If I then go to the portal and execute manually (yes, that particular execution is fired with a null message) it kicks it into life and picks up the other messages on the queue and processes them correctly.

This obviously isn't ideally for our automated tests. Has anybody seen this, or know of anything that will help?

Also, the Function App is running on a consumption plan.

like image 701
pkunal7 Avatar asked Oct 17 '22 10:10

pkunal7


2 Answers

App Service Plan

If you're using App Service plan then it's simple, just make use of Always on

Consumption Plan

If you're using Consumption plan, the issue could be that your triggers did not sync properly with the Azure Infrastructure (Central Listener). It could have happened due to the way you deployed/edited your trigger related settings as explained in issue #210 below.

When you access the function directly from Portal, it might be forcing your function app to come alive, but as you can see that's only a workaround. Something similar is mentioned here

Take a look at these issues:

  1. Service Bus Topic Trigger goes to sleep - Consumption Plan

    They also mention that it wakes up only on accessing it via the portal or calling a HTTP triggered function in the same app, which is similar to the behavior you are seeing.

  2. Issue #210 enter image description here

  3. Issue #681

There are 3 suggested ways to resolve it, mentioned as part of Issue #210 above

In order to synchronize triggers when these deployment options are used, open the Azure Portal and click the Refresh button, or make a API call to the sync triggers endpoint: https://github.com/davidebbo/AzureWebsitesSamples/blob/master/ARMTemplates/FunctionsWebDeploy.json#L90

Powershell sample: https://github.com/davidebbo/AzureWebsitesSamples/blob/master/PowerShell/HelperFunctions.ps1#L360-L365

like image 83
Rohit Saigal Avatar answered Nov 15 '22 10:11

Rohit Saigal


I've had a similar issue. ServiceBus connection was injected using ServiceBus value in ConnectionStrings section of Function configuration. This is enough when Function is in hot state but after transitioning to cold state AzureWebJobsServiceBus value is used to connect to service bus. So in my case setting AzureWebJobsServiceBus to ServiceBus connection string in Function configuration fixed this.

like image 21
asd2ws Avatar answered Nov 15 '22 08:11

asd2ws