简体   繁体   English

Azure 服务总线,一次推送导致 300 条具有相同 ID 的排队消息

[英]Azure Service Bus, one push results in 300 queued messages with the same ID

I have an Azure function which I just updated to look like this:我有一个 Azure 函数,我刚刚将其更新为如下所示:

public void Run([ServiceBusTrigger("xxxx", Connection = "ServiceBusConnectionString", IsSessionsEnabled = true)] Message message, ILogger log, IMessageSession messageSession) public void Run([ServiceBusTrigger("xxxx", Connection = "ServiceBusConnectionString", IsSessionsEnabled = true)] Message message, ILogger log, IMessageSession messageSession)

I did this so I could do this:我这样做是为了我可以这样做:

    var rec = messageSession as MessageReceiver;

    if(rec != null)
    {
        rec.RetryPolicy = Microsoft.ServiceBus.RetryPolicy.NoRetry;
    }

    _event.PushEvent(new Event
    {
        EventName = $"{message.MessageId} - {message.SystemProperties.DeliveryCount}",
        EventData = string.Empty,
        DateOfEvent = DateTime.Now, 
        EventLevel = 1,
        System = Systems.CRMSQL
    }).Wait();
    
    // Manually close message so it won't requeue
    messageSession.CloseAsync().Wait();

My event logging is showing the same message being processed over and over我的事件记录显示正在一遍又一遍地处理相同的消息

    EventName EventData EventLevel DateOfEvent
    5f353e313f104c298bdffa08030d9daa - 1 1 2020-09-03 01:17:47.903
    5f353e313f104c298bdffa08030d9daa - 1 1 2020-09-03 01:17:46.083
    5f353e313f104c298bdffa08030d9daa - 1 1 2020-09-03 01:17:45.227

Why is my function pulling the same message over and over, without the delivery count increasing, even though I am manually closing the message?为什么即使我手动关闭消息,我的函数也会一遍又一遍地拉取相同的消息,而传递计数却没有增加? It did this before I added this code, this is the issue I was trying to resolve.在我添加这段代码之前它就这样做了,这是我试图解决的问题。

My logs confirm we called the function to push into the service bus once.我的日志确认我们调用了一次推送到服务总线的函数。 I log pushing as an event, there is one event log.我将推送记录为一个事件,有一个事件日志。 The graph in Azure shows a jagged climb to 300 messages in the queue. Azure 中的图表显示队列中的消息呈锯齿状攀升至 300 条。

// Manually close message so it won't requeue messageSession.CloseAsync().Wait() // 手动关闭消息,这样它就不会重新排队 messageSession.CloseAsync().Wait()

The function will automatically complete the incoming message once it's done.一旦完成,该功能将自动完成传入的消息。 If you're closing the receiver before incoming message was completed, the message will be redelivered maxDeliveryCount times and you'll see duplicates.如果您在传入消息完成之前关闭接收器,则消息将被重新传递maxDeliveryCount次,您将看到重复。

Not sure what _event.PushEvent is, but if it's your code, you should elaborate what it does.不确定_event.PushEvent是什么,但如果它是你的代码,你应该详细说明它的作用。 Additionally, don't force asynchronous code to run with .Wait() .此外,不要强制异步代码使用.Wait()运行。 Rather use async/await .而是使用async/await

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM