5
votes

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

2
Why do you keep creating new questions very similar to previous ones, without ever responding to answers in those? - Mikhail Shilkov
well, they might be similar but they're not the same! - user1186050
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

2 Answers

2
votes

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

1
votes

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

Please provide you app name.