1
votes

This question is similar to Azure Blob Storage trigger Function not firing

However, their problem was that their Azure Function wasn't awaking immediately, giving the impression it wasn't processing triggers from Azure Blob Storage when in fact it was after 10 minutes which is exactly as the MS docs claim.

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-trigger?tabs=csharp

My problem is different. My blob has been sitting in the container now for 9 hours and it still hasn't been processed.

All it does is post a message onto ServiceBus.

[FunctionName("IncomingFileDetected")]
[return: ServiceBus("incoming-file-received", EntityType = Microsoft.Azure.WebJobs.ServiceBus.EntityType.Topic)]
public static IncomingFile Run(
    [BlobTrigger("incoming-files/{filename}", Connection = "ConnectionStrings:MutableStorage")]
    Stream contents,
    string filename,
    ILogger log)
{
    log.LogInformation($"Detected new blob file: {filename}");
    return new IncomingFile(filename);
}

No messages have appeared in the service bus.

Now, after 9 hours, I have restarted the function app and the blob was processed within about 10 minutes.

1
What kind of AppService plan are you using? If you are not using the Consumption plan, you need to have "Always on" enabled.Alex AIT
Hi @AlexAIT, could you tell me where I have to go to check that?Peter Morris
If you open the function app in the Azure Portal, you can see App Service plan / pricing tier in the middle of the screen next to the status, subscriptionId etc. If it says anything other than "Consumption", e.g. "PremiumV2". Here is a picture: docs.microsoft.com/en-us/azure/azure-functions/… The always on setting is under "configuration - general settings"Alex AIT
Blob will not be removed from blob storage after the function triggered. You can have a look of my code, it works fine both on local and azure.Bowman Zhu

1 Answers

1
votes

Update:

Thanks for Peter Morris's sharing, the problem comes from is service plan is d1. So first make sure you are based on the three kinds of plans: consumption plan, premium plan and app service plan. When we use azure function, even only test, we should use a consumption plan. The smallest in production is S1, which is normally used for testing.

Original Answer:

The below code works fine on my side. Even the consumption plan is no problem.

using System;
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace FunctionApp35
{
    public static class Function1
    {
        [FunctionName("Function1")]
        [return: ServiceBus("test", Connection = "ServiceBusConnection")]
        public static string Run([BlobTrigger("samples-workitems/{name}", Connection = "str")]Stream myBlob, string name, ILogger log)
        {
            log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
            string a = "111111111111111";
            return a;
        }
    }
}

This is my local settings:

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=lti/ThmF+mw9BebOacp9gVazIh76Q39ecikHSCkaTcGK5hmInspX+EkjzpNmvCPWsnvapWziHQHL+kKt2V+lZw==;EndpointSuffix=core.windows.net",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "str": "DefaultEndpointsProtocol=xxxxxx",
    "ServiceBusConnection": "Endpoint=sb://bowmantestxxxxxx"
  }
}

The str is from this place:

enter image description here

The ServiceBusConnection is from this place:

enter image description here

enter image description here

And please notice that the blob will will not be removed from container after the azure function is triggered. Also, dont forget to create at least one subscription in your service bus topic.

enter image description here

All all the above also works fine after the function be deployed to azure.(The difference from local is you need to add settings in configuration settings instead of local.settings.json)

enter image description here

enter image description here