azure - 在服务总线队列触发函数中排队另一条消息时,QueueClient.Complete(Guid) 似乎不起作用

标签 azure azure-servicebus-queues

在 Azure WebJobs 的 OnMessageOptions 类中,我通过设置 AutoComplete 标志来调用 QueueClient.Complete(Guid) 方法设置为 true 并且在运行 ProcessQueue 函数时消息似乎可以正常出队。成功处理每条消息后,事件消息计数将减 1。但是,当我想使用 BrokeredMessage.ScheduledEnqueueTimeUtc 将消息(因为当前无法处理)重新排队回到触发服务总线功能的队列,作为一分钟后的新代理消息,它似乎不起作用。预定消息数最初似乎有所增加。几个小时后,我回到队列,看到数千条活跃消息。这些副本具有相同的消息。怎么了?我希望由于 QueueClient.Complete(Guid) 而将消息从队列中删除,并且新的计划消息将取代它。

一些细节:

要发送消息,我执行以下操作:

var queueclient = QueueClient.CreateFromConnectionString(connectionString, queueName);
queueclient.Send(message);
queueclient.close();

在 WebJob 内部,我创建了一个 ServiceBusConfiguration 对象,该对象需要一个 onMessageOptions 对象,我在其中设置了 AutoComplete=true。我将 ServiceBusConfiguration 对象传递给 JobHostConfiguration.UserServiceBus 方法。

在 WebJob 服务总线队列触发函数中,我再次执行以下操作来重新排队,首先再次创建代理消息的新实例。

//如果尚无法处理,请重新排队...

var queueclient = QueueClient.CreateFromConnectionString(connectionString, queueName);
    queueclient.Send(message);
    queueclient.close();

执行以下/使用回调,这可能是它不起作用的原因?

var options = new OnMessageOptions();
options.AutoComplete = false;  // to call complete ourselves

处理收到消息的回调

client.OnMessage(m =>
{

    var clone = m.Clone();
    clone.ScheduledEnqueueTimeUtc = DateTime.UtcNow.AddSeconds(60);
    client.Send(clone);


    m.Complete();

}, options);

最佳答案

when I want to requeue a message (because it cannot be processed currently) back to the queue that triggers the service bus function, as a new brokered message after a minute, using BrokeredMessage.ScheduledEnqueueTimeUtc, it seems like it isn't working

如果您无法处理消息,请勿重新排队。相反,放弃( with a reason ),它将再次被拾取。

BrokeredMessage.ScheduledEnqueueTimeUtc 用于添加到队列的消息。当您收到消息时,您可以完成、死信、推迟或放弃。如果您放弃一条消息,系统会重试该消息,但您无法控制何时发生。如果队列中没有其他消息,则几乎会立即重试。

注意:当您发现您怀疑不正确的行为时,有一个简单的重现来分享会非常有帮助。

关于azure - 在服务总线队列触发函数中排队另一条消息时,QueueClient.Complete(Guid) 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55481240/

相关文章:

azure - 自动膨胀是否允许在事件中心缩小规模?

azure - "Unsupported app only token"添加证书后仍出现 SharePoint API 错误

azure - 流分析无法立即处理,恒定 5 秒水印

c# - 当消息在几天后进入服务总线队列时,Azure 函数不会被触发

Azure Functions V4 NET 6 服务总线触发器未触发

Azure Functions 和 DocumentDB 触发器

azure - 如何防止恶意带宽吸血鬼请求滥用 Azure CDN 带宽?

azure - 记录 ASP.Net Core 中的错误并能够读取它

azure - 如何通过 Azure ServiceBus 标准计划获得更好的性能

Azure 服务总线 - 消息通信异常 channel 打开超时