简体   繁体   English

死信队列未清除

[英]Dead letter queue not cleared

I have a few messages that were dead lettered automatically due to an exceeded retry count. 我有一些邮件由于超出重试次数而被自动删除。 Now I'm trying the re-queue them like this: 现在,我尝试像这样重新排队:

while ((msg = DeadLetterQueueClient.Receive()) != null)
{
    var body = msg.GetBody<MyModel>();
    QueueClient.Send(new BrokeredMessage(body));
}

I receive all dead lettered messages, however they don't clear from the queue. 我收到了所有字母不正确的邮件,但是它们并未从队列中清除。 Every time I start this code, the same messages are received again. 每次我启动此代码时,都会再次收到相同的消息。

What's wrong? 怎么了?

PS: The queue actually has dead lettering turned off, according to the old Azure portal. PS:根据旧的Azure门户,队列实际上已关闭了死字母。 The messages only show up as dead lettered in Visual Studio Server Explorer and I also receive them with the above code. 这些消息在Visual Studio Server Explorer中仅显示为死信,并且我也收到带有上述代码的消息。

Mark the message as complete and it should be deleted from the dead letter queue 将邮件标记为完成,应将其从死信队列中删除

while ((msg = DeadLetterQueueClient.Receive()) != null)
{
    var body = msg.GetBody<MyModel>();
    QueueClient.Send(new BrokeredMessage(body));
    msg.Complete();
}

如果要保留标题属性,则可能要使用msg.Clone()而不是将正文复制到新的BrokeredMessage中。

You can also try this code to delete a Dead-Lettered message from Queues. 您也可以尝试使用此代码从“队列”中删除“不写信”消息。

  MessageReceiver fromQueueClient = null;

        MessagingFactory factory = MessagingFactory.CreateFromConnectionString(connectionString);
        fromQueueClient = await factory.CreateMessageReceiverAsync(_entityName, ReceiveMode.PeekLock);

            BrokeredMessage _message = await fromQueueClient.ReceiveAsync(SequenceNumber);

                await _message.CompleteAsync();
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Microsoft.Azure.ServiceBus;
    using Microsoft.Azure.ServiceBus.Core;
    using System.Text;
    using System.Collections.Generic;
    using System.Threading.Tasks;

    namespace ClearDeadLetterQ

{
    [TestClass]
    public class UnitTest1
    {

        const string ServiceBusConnectionString = "Endpoint=sb://my-domain.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=yoursharedaccesskeyhereyoursharedaccesskeyhere";


        [TestMethod]
        public async Task TestMethod1()
        {
            await this.ClearDeadLetters("my.topic.name", "mysubscriptionname/$DeadLetterQueue");
        }

        public async Task ClearDeadLetters(string topicName, string subscriptionName)
        {
            var messageReceiver = new MessageReceiver(ServiceBusConnectionString, EntityNameHelper.FormatSubscriptionPath(topicName, subscriptionName), ReceiveMode.PeekLock);
            var message = await messageReceiver.ReceiveAsync();
            while ((message = await messageReceiver.ReceiveAsync()) != null)
            {
                await messageReceiver.CompleteAsync(message.SystemProperties.LockToken);
            }
            await messageReceiver.CloseAsync();
        }
    }
}

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

相关问题 读取MSMQ事务性死信队列 - Reading the MSMQ transactional dead letter queue 如何检索死信队列计数? - How to retrieve Dead Letter Queue count? 使用 RabbitMQ 死信队列消息 - Consume RabbitMQ Dead letter queue messages 通过MessageId在Azure Service Bus死信队列上获取消息 - Getting a Message by MessageId on the Azure Service Bus Dead Letter queue Rabbit-Mq被拒绝后不会路由到死信队列 - Rabbit-Mq not routing to dead letter queue after being rejected 交易死信队列中的MSMQ无效签名错误 - MSMQ invalid signature errors in transacted dead letter queue 死信队列中的服务总线克隆不起作用 - Service Bus Clone from Dead Letter Queue Not Working Azure 服务总线 | 重新处理死信消息返回队列 | 如何接收来自死信队列的所有消息? - Azure service bus | Re process dead letter messages back to queue | How to receive all messages from dead letter queue? 我们可以使用 .net 代码从 Azure 服务总线中的死信队列中删除基于序列号的特定死信消息吗? - can we delete a specific dead letter message based on the sequence number from dead letter queue in Azure service bus using .net code? 我可以获取放入死信/中毒队列的消息的异常或原因吗? - Can I obtain the exception or reason a message put into the dead letter / poison queue?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM