下面的代码可以很好地读取服务总线队列死信,但对于主题,即使更改路径后,它抛出异常路径也不正确。
string path= "QueueName";
MessagingFactory messageFactory = MessagingFactory.CreateFromConnectionString("ConnecitonString");
MessageReceiver deadletterReceiver = await messageFactory.CreateMessageReceiverAsync(QueueClient.FormatDeadLetterPath(path), ReceiveMode.PeekLock);
MessageSender sender = await messageFactory.CreateMessageSenderAsync(path);
BrokeredMessage deadLetter = await deadletterReceiver.ReceiveAsync(TimeSpan.Zero);
if (deadLetter != null)
{
现在我要对Service Bus Topic DeadLetter进行同样的操作
因此路径应为-topicName/subscriptionName
string path= "TopicName/SubscriptionName";
MessagingFactory messageFactory = MessagingFactory.CreateFromConnectionString("ConnecitonString");
MessageReceiver deadletterReceiver = await messageFactory.CreateMessageReceiverAsync(TopicClient.FormatDeadLetterPath(path), ReceiveMode.PeekLock);
MessageSender sender = await messageFactory.CreateMessageSenderAsync(path);
BrokeredMessage deadLetter = await deadletterReceiver.ReceiveAsync(TimeSpan.Zero);
if (deadLetter != null)
{
获取异常路径不正确...
答案 0 :(得分:1)
主题没有死队列,订阅则没有。您需要使用SubscriptionClient.FormatDeadLetterPath(String, String)方法,传递主题和订阅名称。