how to peek and delete a message from deadletter in azureservicebus

左心房为你撑大大i 提交于 2019-12-12 02:56:33

问题


I have created an azure service bus topic application which peek all messages in deadletter. Some specific messages(with particular messageid) which i peeked need to be removed from the deadletter queue. Please provide help for implementing this.


回答1:


By calling complete on the reference to the brokered message you receive from the dead letter queue you can remove it from the dead letter queue.

https://msdn.microsoft.com/library/azure/microsoft.servicebus.messaging.brokeredmessage.complete.aspx




回答2:


First if you need to know how to create a service bus topic and subscription:

  • How to use Service Bus topics and subscriptions

To receive message from a subscription, you need to create a message receiver :

//Create the messaging factory
var messagingFactory = MessagingFactory.CreateFromConnectionString("ServiceBusConnectionString");

// Get the dead letter path
var deadLetterPath = SubscriptionClient.FormatDeadLetterPath("TopicPath", "subscriptionName");

// Get the message receiver for the deal letter queue.
var messageReceiver = messagingFactory.CreateMessageReceiver(deadLetterPath);

Then you can just listen for messages arriving:

// This is the list of ids that need to be delete
var messageIdsToDelete = new List<long>(...);
messageReceiver.OnMessage((message) =>
{
    // Check if we have to delete the message
    if (messageIdsToDelete.Contains(message.SequenceNumber))
    {
        // Complete and delete the message from the queue.
        message.Complete();
    }

}, new OnMessageOptions());



回答3:


This code helps you to delete a dead-letter message in Azure service bus.

MessageReceiver fromQueueClient = null;

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

            BrokeredMessage _message = await fromQueueClient.ReceiveAsync(SequenceNumber);

                await _message.CompleteAsync();


来源:https://stackoverflow.com/questions/35191298/how-to-peek-and-delete-a-message-from-deadletter-in-azureservicebus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!