2

很难找到一些好的文档来获取死信队列中的所有消息并查看它们。

我有一个 Azure 服务总线队列,我能找到的所有内容都是针对 Azure 服务总线主题的。

有人可以帮助我快速指南吗?

4

4 回答 4

4

死信队列是有害消息移动到的辅助子队列。

在 Azure Servicebus Queue 的情况下,DLQ 的标准路径是queuePath/$DeadLetterQueue. 所以你需要另一个queueClient来阅读 DLQ。

您将在 .NET 客户端中执行类似的操作。

string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
var client = QueueClient.CreateFromConnectionString(connectionString, "QueueName");

// do whatever regular queue reading activities

// this is for dead letter queue
var deadLetterClient = QueueClient.CreateFromConnectionString(connectionString, QueueClient.FormatDeadLetterPath(client.Path), ReceiveMode.ReceiveAndDelete);

BrokeredMessage receivedDeadLetterMessage;
while ((receivedDeadLetterMessage = deadLetterClient.Receive(TimeSpan.FromSeconds(10))) != null)
{
    Console.WriteLine(receivedDeadLetterMessage);
}
于 2016-08-05T08:18:03.580 回答
2

Azure 门户现在提供服务总线资源管理器(预览版)工具,可直接从门户本身对队列/主题及其死信子实体执行基本操作(例如发送、接收、查看)。查看此链接,了解有关使用此工具的详细说明 - azure-service-bus-messaging-explorer服务总线资源管理器 Azure 门户

要使用更高级的功能,例如导入/导出功能或测试主题、队列、订阅、中继服务、通知中心和事件中心的能力,请尝试使用社区拥有的运营支持系统 (OSS) 工具服务总线浏览器。 服务总线浏览器 与今天一样,您只能在 Azure 门户上的服务总线资源管理器预览版上查看 32 条消息。因此,如果您有更多消息要处理,那么您可能希望选择上述独立的社区拥有的 OSS 工具。

于 2020-06-25T15:03:53.390 回答
0
string connectionString = ConfigurationManager.AppSettings["connectionString"];    
string queueName = ConfigurationManager.AppSettings["queueName"];    
ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(connectionString);    
MessagingFactory factory = MessagingFactory.CreateFromConnectionString(builder.ToString());    
var client = QueueClient.CreateFromConnectionString(connectionString, queueName);    
string deadLetterQueuePath = QueueClient.FormatDeadLetterPath(queueName);    
QueueClient deadletterQueueClient = factory.CreateQueueClient(deadLetterQueuePath);    
while (true)    
{    
       BrokeredMessage brokeredMessage = deadletterQueueClient.Receive();    
       // Your Logic    
}
于 2017-02-22T14:23:00.877 回答
0

下面是一个示例,说明如何使用 Peek 获取死信队列中所有消息的列表:

public async Task<IEnumerable<BrokeredMessage>> GetDeadLetterMessagesAsync(string connectionString,
    string queueName)
{
    var queue = QueueClient.CreateFromConnectionString(connectionString, QueueClient.FormatDeadLetterPath(queueName));
    var messageList = new List<BrokeredMessage>();
    BrokeredMessage message;
    do
    {
        message = await queue.PeekAsync();
        if (message != null)
        {
            messageList.Add(message);
        }
    } while (message != null);
    return messageList;
}
于 2017-09-07T12:43:46.837 回答