0

我创建了一个 azure 服务总线主题应用程序,它可以查看deadletter中的所有消息。我偷看的一些特定消息(具有特定的 messageid)需要从死信队列中删除。请为实施此提供帮助。

4

3 回答 3

3

通过对您从死信队列收到的代理消息的引用调用完成,您可以将其从死信队列中删除。

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

于 2016-02-04T03:38:54.657 回答
3

首先,如果您需要知道如何创建服务总线主题和订阅:

要从订阅接收消息,您需要创建一个消息接收器:

//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);

然后你可以只收听到达的消息:

// 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());
于 2016-02-04T21:38:14.350 回答
0

此代码可帮助您删除 Azure 服务总线中的死信消息。

MessageReceiver fromQueueClient = null;

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

            BrokeredMessage _message = await fromQueueClient.ReceiveAsync(SequenceNumber);

                await _message.CompleteAsync();
于 2018-10-04T10:06:57.133 回答