6

I have a service bus queue in Azure and a service bus queue trigger function. When I first publish the function and send a message to the service bus queue the function gets triggered and runs ok.

But if I leave it alone and don't send any messages to the queue for say ~ 1 hour and then I send a message the function doesn't get triggered. I have to manually run the function again in the portal by pressing 'run' or I have to re-publish it to Azure.

How do I keep it running so I don't have to restart it every hour or so??? My app might not send a new message to the queue for a couple of hours or even days.

FYI - I read here that the function shuts down after 5 minutes, I can't use functions if this is the case and I don't want to use a timer trigger because then I'd be running the function more then I would want, wasting money! Right? If my only, best, choice here is to run a timer function every 30 minutes throughout the day I might just have to suck it up and do it this way, but I'd prefer to have the function run when a message hits the message queue.

FYI2 - ultimately I want to hide the message until a certain date, when I first push it to the queue (ex. set to show 1 week from the time it's placed in the queue). What am I trying to accomplish? I want to send an email out to registered students after a class has ended, and the class might be scheduled 1-30 days in advance. So when the class is scheduled I don't want the function to run until after the class ends, which might be 1 week, 2 weeks 2 days, 3 weeks 3 days, etc after the class is initially scheduled in my app.

Here is the snippet from the function.json

{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
"configurationSource": "attributes",
"bindings": [
{
  "type": "serviceBusTrigger",
  "connection": "Yogabandy2017_RootManageSharedAccessKey_SERVICEBUS",
  "queueName": "yogabandy2017",
  "accessRights": "listen",
  "name": "myQueueItem"
}
],
"disabled": false,
"scriptFile": "..\\bin\\PostEventEmailFunction.dll",
"entryPoint": "PostEventEmailFunction.Function1.Run"
}

Here is the function

public static class Function1
{
    [FunctionName("Function1")]
    public static void Run([ServiceBusTrigger("yogabandy2017", AccessRights.Listen, Connection = "Yogabandy2017_RootManageSharedAccessKey_SERVICEBUS")]string myQueueItem, TraceWriter log)
    {
        log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}");


    }
}

I've been asked to post my payment plan

enter image description here

chuckd
  • 13,460
  • 29
  • 152
  • 331
  • 1
    Why do you keep creating new questions very similar to previous ones, without ever responding to answers in those? – Mikhail Shilkov Dec 10 '17 at 08:45
  • well, they might be similar but they're not the same! – chuckd Dec 10 '17 at 09:29
  • Have you tried giving the function MANAGE rights on the queue? ("accessRights": "manage") I know there have been some issues in the past where only the listen permission tricked the function into thinking it had nothing to do... – Niels Dec 12 '17 at 15:51

2 Answers2

2

I suspect you're using scenario 1 and 2 below - which will shutdown after a period of no activity.

  1. The Function app on a Free/Shared App Service Plan. Always On is not available, so you'll have the upgrade your plan.

  2. The Function App on a Basic/Standard/Premium App Service Plan. You'll need to ensure the Always On is checked in the function Application Setting

  3. If the Function App using a Consumption Plan, this should work. It will wake up the function app on each request. For your scenario I would recommend this approach as it only utilises resources when required.

FYI1 - If you get the above working, you won't need the timer.

A Consumption Plan in the Application Settings will look like: Azure Function Consumption Plan

Jason Jong
  • 4,310
  • 2
  • 25
  • 33
  • Hi Jason. Based on what I think I've set up under my Azure account, it looks like I created pay-as-you-go. I'm trying to find where in the function application settings I can check off the always on button but I don't see it anywhere. I know I can set the daily quota limit which shuts off the app if I've hit that limit, so I think I might already be on a consumption plan!? – chuckd Dec 12 '17 at 22:29
  • @user1186050 - Its quite hard to find actually. In your Function App, you'll start off in the Overview tab, then you'll see "Configured features" heading. Under it click on "Application settings". – Jason Jong Dec 12 '17 at 22:57
  • I see where both the application settings and the function app settings links are and I can click on both, I just don't see where in either section I can see anything that shows the plan other then 'pay-as-you-go', which is the plan I have configured for my account. Question - isn't the pay-as-you-go the same as the consumption plan? – chuckd Dec 13 '17 at 00:08
  • Hi @user1186050 - In the Application Function settings, you will see the "Application Service Plan". Does it say something along the lines of "App Service plan / pricing tier - CentralUSPlan (Consumption)" ? If it doesn't, you'll have to create a new Function App. You will get then chance to setup the correct Service Plan via a dropdown. – Jason Jong Dec 15 '17 at 00:36
  • I see 'WestUSPlan(Consumption)' I'll post the plan pic in the original post. – chuckd Dec 15 '17 at 01:04
1

Please check your service plan by 1. Platform features 2. App Service plan 3. under Pricing Tier

Please provide you app name.

patrick
  • 21
  • 5
  • I think I found the reason! The connection string name used isn't correct. – chuckd Dec 15 '17 at 05:37
  • Glad you found the issue, I am surprised that it worked at all. To ensure the connection string is correct, go the service bus and obtain from the shared access policies. Alternatively, you can use ARM templates, but thats another topic. – Jason Jong Dec 19 '17 at 00:02