Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you access the dead letter sub-queue on an Azure subscription?

When I use the following:

var deadLetterPath = SubscriptionClient.FormatDeadLetterPath(topicPath,subName);
var client = SubscriptionClient.CreateFromConnectionString(connectionString, deadLetterPath, subName);

I get an InvalidOperationException

Cannot directly create a client on a sub-queue. Create a client on the main queue and use that to create receivers on the appropriate sub-queue

Some parts of the azure documentation say to use SubscriptionClient.CreateReceiver to access a sub-queue but that method doesn't exist.

like image 443
kareem Avatar asked Mar 27 '14 08:03

kareem


People also ask

How do you access the dead-letter queue in Azure Service Bus?

To receive messages from DLQ through SB explorer, you need to click on that particular queue and then click on “Deadletter” tab then one dialogue box will pop up then you need to click on “Receive and Delete”. The default value is Top10 so top10 messages will be received from DLQ.

How do you process a dead-letter queue?

To process messages on a dead-letter queue (DLQ), IBM® MQ supplies a default DLQ handler. The handler matches messages on the DLQ against entries in a rules table that you define. Messages can be put on a DLQ by queue managers, message channel agents (MCAs), and applications.

How do I view message queue in Azure?

Peek a message With the peek functionality, you can use the Service Bus Explorer to view the top 100 messages in a queue, subscription or dead-letter queue. To peek messages, select Peek Mode in the Service Bus Explorer dropdown.

Where are the expired messages in queue stored?

Expired messages moved to the dead-letter queue can be distinguished from other dead-lettered messages by evaluating the dead-letter reason property that the broker stores in the user properties section.

What happens if there is no dead-letter queue?

If the dead-letter queue is not available, the sending MCA leaves the message on the transmission queue, and the channel stops. On a fast channel, nonpersistent messages that cannot be written to a dead-letter queue are lost.


2 Answers

Does this approach work for you ?

MessagingFactory factory = MessagingFactory.CreateFromConnectionString(cnxString);
var deadLetterPath = SubscriptionClient.FormatDeadLetterPath(topicPath,subName);
var dlqReceiver = factory.CreateMessageReceiver(deadLetterPath, ReceiveMode.ReceiveAndDelete);

I haven't test it out here (in a meeting), but give it a try

cheers

like image 142
Sam Vanhoutte Avatar answered Oct 19 '22 09:10

Sam Vanhoutte


There is a convention naming for Dead letter queue using Azure Service Bus:

  • For Service Bus Queue: queuePath/$DeadLetterQueue
  • For Service Bus Subscription: topicPath/subscriptionName/$DeadLetterQueue

So you can access your dead letter queues the same way you access your queues.

From @SamVanhoutte answer, you can see that the ServiceBus framework provides methods to format the dead letter queue name:

  • For Service Bus Queue: QueueClient.FormatDeadLetterPath(queuePath)

  • For Service Bus Subscription: SubscriptionClient.FormatDeadLetterPath(topicPath, subscriptionName)

I wrote two small methods to create a message receiver for queue and subscription where you can set if you want the deal letter queue or not:

/// <summary>
/// Create a new <see cref="MessageReceiver"/> object using the specified Service Bus Queue path.
/// </summary>
/// <param name="connectionString">The connection string to access the desired service namespace.</param>
/// <param name="queuePath">The Service Bus Queue path.</param>
/// <param name="isDeadLetter">True if the desired path is the deadletter queue.</param>
public static MessageReceiver CreateMessageReceiver(string connectionString, string queuePath,
    bool isDeadLetter = false)
{
    return MessagingFactory.CreateFromConnectionString(connectionString)
        .CreateMessageReceiver(isDeadLetter
            ? QueueClient.FormatDeadLetterPath(queuePath)
            : queuePath);
}

/// <summary>
/// Create a new <see cref="MessageReceiver"/> object using the specified Service Bus Topic Subscription path.
/// </summary>
/// <param name="connectionString">The connection string to access the desired service namespace.</param>
/// <param name="topicPath">The Service Bus Topic path.</param>
/// <param name="subscriptionName">The Service Bus Topic Subscription name.</param>
/// <param name="isDeadLetter">True if the desired path is the deadletter subqueue.</param>
public static MessageReceiver CreateMessageReceiver(string connectionString, string topicPath,
    string subscriptionName, bool isDeadLetter = false)
{
    return MessagingFactory.CreateFromConnectionString(connectionString)
        .CreateMessageReceiver(isDeadLetter
            ? SubscriptionClient.FormatDeadLetterPath(topicPath, subscriptionName)
            : SubscriptionClient.FormatSubscriptionPath(topicPath, subscriptionName));
}
like image 16
Thomas Avatar answered Oct 19 '22 09:10

Thomas