Launch price: every exam for $29.99 a year, for the first 300 buyers. See the price

CertStreak
Menu

Queue and process back-end operations by using Azure Service Bus, including dead-letter queue handling, messages, topics, and subscriptions

A worked example

Single answer

A Python worker uses the azure-servicebus SDK and a ServiceBusClient instance named client. Some inference requests sent to an existing Service Bus queue named inference-requests were dead-lettered. You need to read the messages held in the dead-letter subqueue of that queue so that you can inspect their dead_letter_reason property.

Which receiver should you create?

Choose one answer
Why

Every queue has an automatically created dead-letter subqueue. In the Python SDK you read it by creating a normal queue receiver with sub_queue=ServiceBusSubQueue.DEAD_LETTER, and the SDK handles the path internally. Each dead-lettered message then exposes dead_letter_reason and dead_letter_error_description for diagnosis.

  • Not correct: client.get_subscription_receiver(topic_name="inference-requests", subscription_name="deadletter"). A subscription receiver connects to a subscription on a topic. The entity here is a queue, and its dead-letter queue is a subqueue, not a subscription.
  • Not correct: client.get_queue_receiver(queue_name="inference-requests", receive_mode=ServiceBusReceiveMode.RECEIVE_AND_DELETE). The receive mode only controls settlement. RECEIVE_AND_DELETE removes messages on receipt. Without the sub_queue parameter, this receiver reads the main queue, not its dead-letter subqueue.
  • Correct: client.get_queue_receiver(queue_name="inference-requests", sub_queue=ServiceBusSubQueue.DEAD_LETTER). The SDK reaches the dead-letter subqueue of a queue through the sub_queue parameter set to ServiceBusSubQueue.DEAD_LETTER on the queue receiver, and the dead-lettered messages expose dead_letter_reason.
  • Not correct: client.get_queue_receiver(queue_name="inference-requests", session_id="deadletter"). The session_id parameter opens a receiver for a session on a session-enabled queue. Sessions provide FIFO, single-receiver processing. This parameter does not target the dead-letter subqueue.

Practise this topic until it's automatic.

Ten questions a day, every answer explained, and misses that come back until you beat them.

Start free