Sameer Tanveer
Sameer Tanveer

Reputation: 11

Azure Queue Trigger is hit but not executing the logic inside of it

I have an azure queue trigger and when I add a new message to the queue it gets picked up by the trigger but the logic within the function itself is not being executed.

Message we see in console...

Executing 'Functions.ProcessVoidData' (Reason='New queue message detected on 'void-queue'.', Id=a402eaf8-5885-4246-bf83-66eb026b65c2)
[2025-01-23T11:01:29.323Z] Trigger Details: MessageId: 38d917df-3217-4397-9149-eaeb05f05b7d, DequeueCount: 1, InsertedOn: 2025-01-23T11:01:28.000+00:00
[2025-01-23T11:01:29.361Z] Executed 'Functions.ProcessVoidData' (Succeeded, Id=a402eaf8-5885-4246-bf83-66eb026b65c2, Duration=44ms)

I have verified these files and they don't seem to have an issue. The connection string is correct and there seems to be no configuration issues with it. The packages are up to date as well.

host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      },
      "enableLiveMetricsFilters": true
    }
  }
}

Found the same problem but wasn't able to solve my issue : Redit

GitHUb issue

public async Task Run([QueueTrigger(QueueName, Connection = EnvironmentVariable.storageAcc)] QueueModel queueModel)
{
    var data = queueModel.Data;

    try
    {
       //Logic
    }
    catch (Exception e)
    {
        _logger.LogCritical(ConstantsMessages.EXCEPTION + ConstantsMessages.SingleSpace + $"{e.Message}");
        _logger.LogCritical(e.StackTrace);
    }
}

Upvotes: 0

Views: 77

Answers (1)

Ikhtesam Afrin
Ikhtesam Afrin

Reputation: 6464

  • If you are executing the code locally, then I would recommend you to add the debugger and check.

  • I have used a redacted version of your code to log the values which are being passed in the queue message.

using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

namespace FunctionApp15
{
    public class Function1
    {
        [FunctionName("Function1")]
        public void Run([QueueTrigger("myqueue", Connection = "VoidStorageAccount")] VoidDataQueueDto voidQueueDto, ILogger log)
        {
            var voidRawData = voidQueueDto.VoidData;

            log.LogInformation($"Handle Id: {voidRawData.HandleId}");
            log.LogInformation($"Blob Id: {voidRawData.RawDataBlobId}");
        }
    }
}

Here, I am able to get the logged values successfully.

Azure Functions Core Tools
Core Tools Version:       4.0.6518 Commit hash: N/A +74ed9095fdd6c5326276aae6b8a7d41ccbdeb6aa (64-bit)
Function Runtime Version: 4.35.4.23179

[2025-01-24T06:02:51.994Z] Found C:\Users\***\FunctionApp15\FunctionApp15\FunctionApp15.csproj. Using for user secrets file configuration.

Functions:

        Function1: queueTrigger

For detailed output, run func with --verbose flag.
[2025-01-24T06:02:58.970Z] Host lock lease acquired by instance ID '0000000000000000000000000D2022A4'.
[2025-01-24T06:03:09.693Z] Executing 'Function1' (Reason='New queue message detected on 'myqueue'.', Id=265dbfd7-ad57-4d45-9ac5-3bd77909e589)
[2025-01-24T06:03:09.695Z] Trigger Details: MessageId: a4bcd906-6601-4fec-87ec-c00a1c8091a1, DequeueCount: 1, InsertedOn: 2025-01-24T06:03:06.000+00:00
[2025-01-24T06:03:09.705Z] Handle Id: HND12345
[2025-01-24T06:03:09.708Z] Blob Id: blob-12345678-abcd-efgh-ijkl-1234567890ab
[2025-01-24T06:03:09.726Z] Executed 'Function1' (Succeeded, Id=265dbfd7-ad57-4d45-9ac5-3bd77909e589, Duration=68ms)

Update :-

If you are creating an isolated queue triggered function, then you should have below codes in the mentioned files.

using System;
using Azure.Storage.Queues.Models;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

namespace FunctionApp16
{
    public class Function1
    {
        private readonly ILogger<Function1> _logger;

        public Function1(ILogger<Function1> logger)
        {
            _logger = logger;
        }

        [Function(nameof(Function1))]
        public void Run([QueueTrigger("myqueue", Connection = "VoidStorageAccount")] QueueMessage message)
        {
            _logger.LogInformation($"C# Queue trigger function processed: {message.MessageText}");
        }
    }
}

.csproj :-

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.5.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
  </ItemGroup>
</Project>

Local settings :-

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
    "VoidStorageAccount": "BlobEndpoint=https://afrinstore1.blob.core.windows.net/;QueueEndpoint=https://afrinstore1.queue.core.windows.net/;FileEndpoint=https://afrinstore1.file.core.windows.net/;TableEndpoint=https://afrinstore1.table.core.windows.net/;SharedAccessSignature=sv=2022-11-02&ss=bfqt&srt=sco&sp=rwdlacupiytfx&se=2025-01-24T16:17:07Z&st=2025-01-24T08:17:07Z&spr=https&sig=BsC%*****g%3D"
  }
}

Response :-

Azure Functions Core Tools
Core Tools Version:       4.0.6821 Commit hash: N/A +c09a2033faa7ecf51b3773308283af0ca9a99f83 (64-bit)
Function Runtime Version: 4.1036.1.23224

[2025-01-24T08:21:27.751Z] Found C:\Users\*****\FunctionApp16\FunctionApp16\FunctionApp16.csproj. Using for user secrets file configuration.
[2025-01-24T08:21:30.062Z] Azure Functions .NET Worker (PID: 27740) initialized in debug mode. Waiting for debugger to attach...
[2025-01-24T08:21:30.103Z] Worker process started and initialized.

Functions:

        Function1: queueTrigger

For detailed output, run func with --verbose flag.
[2025-01-24T08:21:35.179Z] Host lock lease acquired by instance ID '0000000000000000000000000D2022A4'.
[2025-01-24T08:22:05.348Z] Executing 'Functions.Function1' (Reason='New queue message detected on 'myqueue'.', Id=0cdcf231-c7e9-4cfb-8b41-e4e19ccafeaf)
[2025-01-24T08:22:05.352Z] Trigger Details: MessageId: f96ecdab-72d9-4075-b5f5-241c11cf520b, DequeueCount: 1, InsertedOn: 2025-01-24T08:22:04.000+00:00
[2025-01-24T08:22:05.488Z] C# Queue trigger function processed: Hello Afreen
[2025-01-24T08:22:05.508Z] Executed 'Functions.Function1' (Succeeded, Id=0cdcf231-c7e9-4cfb-8b41-e4e19ccafeaf, Duration=216ms)

Upvotes: 0

Related Questions