You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Queue Trigger函数将消息立即移入Poison Queue的问题解决求助

Azure Queue Trigger函数将消息立即移入Poison Queue的问题解决求助

我写了一个基础的Azure HTTP触发函数,每次收到POST请求时会往Azure队列里发送任务消息,代码如下:

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Azure.Storage.Queues;

namespace WeatherImageGenerator.HTTP
{
    public class StartJobFunction
    {

        private readonly ILogger<StartJobFunction> _logger;
        
        public StartJobFunction(ILogger<StartJobFunction> logger)
        {
            _logger = logger;
        }

        [Function("StartJobFunction")]
        public async Task<IActionResult> Run (
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req)
            {
                _logger.LogInformation("Received request to start a job.");

                var jobId = Guid.NewGuid().ToString();

                var message = JsonConvert.SerializeObject(new { JobId = jobId, Status = "Pending"});

                string connectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
                QueueClient queueClient = new QueueClient(connectionString, "startjobqueue");

                await queueClient.CreateIfNotExistsAsync();

                await queueClient.SendMessageAsync(message);

                _logger.LogInformation($"Sent message to start job queue for job {jobId}");

                return new OkObjectResult(new { JobId = jobId });
            }
    }
}

但问题来了,只要我给这个队列添加一个Azure Queue Trigger函数(哪怕是VSCode自动生成的默认代码),所有发送到队列的消息都会瞬间达到MaxDequeueCount的上限5次,直接被移到死信队列里去了。而且Trigger函数里的日志信息完全没输出,就像根本没执行过一样。

附上我用的默认生成的Queue Trigger函数代码:

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

namespace WeatherImageGenerator.Queue
{
    public class ProcessStartJobQueue
    {
        private readonly ILogger<ProcessStartJobQueue> _logger;

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

        [Function(nameof(ProcessStartJobQueue))]
        public void Run([QueueTrigger("startjobqueue", Connection = "AzureWebJobsStorage")] QueueMessage message)
        {
            _logger.LogInformation($"C# Queue trigger function started for message: {message.MessageText}");
        }
    }
}

有没有大佬能帮我看看这是哪里出问题了,怎么解决这个消息直接进死信队列的情况?

备注:内容来源于stack exchange,提问作者Ignacio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 09:12:57