5

Error : Message has reached MaxDequeueCount of 5. Moving message to queue 'webjobs-blobtrigger-poison'. when I tried to put a new file in Container in Azure, I got 5 failed action and this message : Message has reached MaxDequeueCount of 5. Moving message to queue 'webjobs-blobtrigger-poison'.

this is my code :

using System;
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Xml;
using System.Threading.Tasks;

namespace dynamicFileRepository
{
    [StorageAccount("BlobConnectionString")]
    public class copyBlobtoazureStorage
    {
       
        [FunctionName("copyBlobtoazureStorage")]
        public void Run(
            [BlobTrigger("input-file/{name}")] Stream inputBlob,
            [Blob("output-file/{name}", FileAccess.Write)] Stream outputBlob,
            string name, ILogger log, ExecutionContext context)
        {

            XmlDocument doc = new XmlDocument();
            using (XmlReader reader = XmlReader.Create(inputBlob))
            {
                doc.Load(reader);
            }
            string jsonText = JsonConvert.SerializeXmlNode(doc);
            Console.WriteLine(jsonText);

            log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {inputBlob.Length} Bytes");
        

       
    }
    }
}

this is the output window :

enter image description here

2 Answers2

8

I've had this issue a couple of times and the reason both times has been because I've not base64 encoded the payload I'm adding to the queue.

var queueClient = new QueueClient(connectionString, "my-queue");
var bytes = Encoding.UTF8.GetBytes(message);
await queueClient.SendMessageAsync(Convert.ToBase64String(bytes));

It's frustrating that the error message isn't more revealing. And, in fact somebody has raised this issue with the Azure team.

Luke Garrigan
  • 4,571
  • 1
  • 21
  • 29
6

I recently having this problem too. I have a Blazor app which enqueue messages to Azure Queue and a second Azure Functions to dequeue and process it, but somehow the Azure Functions don't want to process the message and the message ends up in the poison queue.

It turns out the message encoding is different between Azure.Storage.Queue (defaults to None) and the one used in WebJobs (Function App defaults to Base64). The solution is to make sure both app uses the same encoding.

In your host.json file, add this code:

{
  "version": "2.0",
  "extensions": {
    "queues": {
      "messageEncoding": "base64" // or "none"
    }
  }
}

And in the other app where you want to publish the message, set the appropriate encoding via QueueClientOptions

var client = new QueueClient("ConnectionString", "QueueName", new QueueClientOptions
{
    MessageEncoding = QueueMessageEncoding.Base64 // or QueueMessageEncoding.None
});

Also when you're adding a new message to the queue, don't forget to tick the Encode the message body in Base64 encoding depending on whether you want to use Base64 or not.

enter image description here

Fahmi Noor Fiqri
  • 441
  • 7
  • 15