0

I have an Azure Storage Queue that gets messages from an IoT device. The messages are not Base64 encoded, compressed or anything else. They are plain old UTF-8. Here's a sample message:

{"id":"649251ce-5b46-9e3b-ac63-15fe4ffb852c","topic":"/SUBSCRIPTIONS/2BA02699-F96D-4474-BC02-888E2CF968F8/RESOURCEGROUPS/MYRESOURCEGROUP/PROVIDERS/MICROSOFT.DEVICES/IOTHUBS/DVV1234","subject":"devices/DT12345","eventType":"Microsoft.Devices.DeviceTelemetry","eventTime":"2024-12-12T14:20:13.311Z","data":{"properties":{"alarm":"","history":null,"current":null,"devicemsg":null,"mqtt-dup":null},"systemProperties":{"iothub-connection-device-id":"DV12345","iothub-connection-auth-method":"{\"scope\":\"device\",\"type\":\"sas\",\"issuer\":\"iothub\"}","iothub-connection-auth-generation-id":"637432295369411031","iothub-enqueuedtime":"2024-12-12T14:20:13.311Z","iothub-message-source":"Telemetry"},"body":"IHsiRFQiOnsiVCI6ICIyMDI0LTEyLTEyIDE0OjIwOjE1In0gLCAiVW5pdCI6eyJJRCI6IjEwMTIzNDUiLCJOYW1lIjoiRFQxMjM0NSJ9LCAiQVMiOltdfQ=="},"dataVersion":"","metadataVersion":"1"}

My Azure queue triggered function is not reading these messages. Instead, it is just logging this message to the console for every message that drops in the queue: [2024-12-12T14:31:09.342Z] Message has reached MaxDequeueCount of 5. Moving message to queue 'mqtt-inbound-poison'.

I have stripped the code down to the most basic queue trigger function app: Program.cs:

using Microsoft.Azure.Functions.Worker.Builder; using Microsoft.Extensions.Hosting; var builder = FunctionsApplication.CreateBuilder(args); builder.ConfigureFunctionsWebApplication(); // Application Insights isn't enabled by default. See https://aka.ms/AAt8mw4. // builder.Services // .AddApplicationInsightsTelemetryWorkerService() // .ConfigureFunctionsApplicationInsights(); builder.Build().Run(); 

Function1.cs:

using System; using Azure.Storage.Queues.Models; using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.Logging; namespace inboundtest { public class Function1 { private readonly ILogger<Function1> _logger; public Function1(ILogger<Function1> logger) { _logger = logger; } [Function(nameof(Function1))] public void Run([QueueTrigger("mqtt-inbound", Connection = "MyStorage")] QueueMessage message) try { _logger.LogInformation($"C# Queue trigger function processed: {message.MessageText}"); } catch { _logger.LogError("An error occurred processing the message."); } } } } 

But the message about the MaxDequeueCount is all I get. I am 100% certain my queue name, mqtt-inbound, is correct. I am also certain the connection string is correct as I selected the storage account in Visual Studio when creating the project. I just built this minimal test code this morning and I am using the latest and greatest NuGet packages. Since neither my try nor catch message is being logged to the console, I suspect something is occurring before my function has even run, but what? What are my next steps in troubleshooting this?

2
  • Can You try logging the message directly in your function to see if it is being received correctly or not?. Commented Dec 13, 2024 at 3:53
  • Check the connection string in your local.settings.json file to ensure it is correctly set up. Commented Dec 13, 2024 at 3:54

1 Answer 1

0

You need to encode the message to Base64 while sending for Queue storage function to execute.

Checkout the Usage of Azure Queue storage triggered function app which says below :-

Functions expect a base64 encoded string. Any adjustments to the encoding type (in order to prepare data as a base64 encoded string) need to be implemented in the calling service.

I am sending the same message as given below-

enter image description here

Your function will trigger as expected.

Azure Functions Core Tools Core Tools Version: 4.0.6610 Commit hash: N/A +0d55b5d7efe83d85d2b5c6e0b0a9c1b213e96256 (64-bit) Function Runtime Version: 4.1036.1.23224 [2024-12-13T13:11:29.284Z] Found C:\Users\****\source\repos\79275973\79275973\79275973.csproj. Using for user secrets file configuration. [2024-12-13T13:11:32.640Z] Azure Functions .NET Worker (PID: 16076) initialized in debug mode. Waiting for debugger to attach... [2024-12-13T13:11:32.691Z] Worker process started and initialized. Functions: Function1: queueTrigger For detailed output, run func with --verbose flag. [2024-12-13T13:11:37.779Z] Host lock lease acquired by instance ID '0000000000000000000000000D2022A4'. [2024-12-13T13:16:10.643Z] Executing 'Functions.Function1' (Reason='New queue message detected on 'mqtt-inbound'.', Id=2433e395-bfc6-4179-8d92-18ced5c5d629) [2024-12-13T13:16:10.645Z] Trigger Details: MessageId: 897e917a-02d6-42e5-b64f-2b27deca77aa, DequeueCount: 1, InsertedOn: 2024-12-13T13:16:07.000+00:00 [2024-12-13T13:16:10.770Z] C# Queue trigger function processed: { "id":"649251ce-5b46-9e3b-ac63-15fe4ffb852c", "topic":"/SUBSCRIPTIONS/2BA****68F8/RESOURCEGROUPS/MYRESOURCEGROUP/PROVIDERS/MICROSOFT.DEVICES/IOTHUBS/DVV1234", "subject":"devices/DT12345", "eventType":"Microsoft.Devices.DeviceTelemetry", "eventTime":"2024-12-12T14:20:13.311Z", "data": { "properties": { "alarm":"", "history":null, "current":null, "devicemsg":null, "mqtt-dup":null }, "systemProperties": { "iothub-connection-device-id":"DV12345", "iothub-connection-auth-method":"{\"scope\":\"device\",\"type\":\"sas\",\"issuer\":\"iothub\"}", "iothub-connection-auth-generation-id":"637432295369411031", "iothub-enqueuedtime":"2024-12-12T14:20:13.311Z", "iothub-message-source":"Telemetry" }, "body":"IHsiRFQiOnsiVCI6ICIyMDI0LTEyLTEyIDE0OjIwOjE1In0gLCAiVW5pdCI6eyJJRCI6IjEwMTIzNDUiLCJOYW1lIjoiRFQxMjM0NSJ9LCAiQVMiOltdfQ==" }, "dataVersion":"", "metadataVersion":"1" } [2024-12-13T13:16:10.809Z] Executed 'Functions.Function1' (Succeeded, Id=2433e395-bfc6-4179-8d92-18ced5c5d629, Duration=206ms) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.