Home › Studies › AI-200 › Messaging & Functions › Service Bus & Event Grid

Service Bus & Event Grid

queues · topics and subscriptions · peek-lock and settlement · dead-letter queues · rules and filters · Event Grid custom topics, filters and retries

By the tools4free.dev team · Last reviewed November 13, 2026

Practice questions for this topic →

Service Bus queues, topics and subscriptions

QueueTopic and subscriptions
PatternPoint-to-pointPublish/subscribe (one-to-many)
DeliverySingle consumer per message (competing consumers)Each subscription receives a copy
FilteringNot supportedSubscription rules and filters
Typical useTask distribution, load levelingEvent broadcasting, fan-out

Receive modes

ModeWhat happensFailure result
Receive and deleteThe message is settled when the broker sends itA consumer crash before processing loses the message (at-most-once)
Peek lockTwo stages: the message is locked, then you settle itA crash after processing but before completing leads to redelivery (at-least-once)

Send and receive with the Python SDK

The Python quickstarts use the azure-servicebus package. The passwordless tab creates DefaultAzureCredential() (from azure.identity.aio) and passes it to ServiceBusClient with the fully qualified namespace.

TaskCall
Queue senderservicebus_client.get_queue_sender(queue_name=QUEUE_NAME)
Topic senderservicebus_client.get_topic_sender(topic_name=TOPIC_NAME)
Send one messagemessage = ServiceBusMessage("Single Message") then await sender.send_messages(message)
Send a batchbatch_message = await sender.create_message_batch(), then batch_message.add_message(...); a ValueError means the batch reached max_size
Queue receiverservicebus_client.get_queue_receiver(queue_name=QUEUE_NAME)
Subscription receiverservicebus_client.get_subscription_receiver(topic_name=TOPIC_NAME, subscription_name=SUBSCRIPTION_NAME, max_wait_time=5)
Receiveawait receiver.receive_messages(max_wait_time=5, max_message_count=20)
Settle (complete)await receiver.complete_message(msg) removes the message from the queue

The quickstart receiver reads until no new message arrives for 5 seconds (max_wait_time).

Settlement, locks and dead-letter queues

SettlementEffect in peek-lock mode
CompleteSuccess: the message is removed from the queue or subscription
AbandonReleases and unlocks the message at once so it can be delivered again
Let the lock expireThe message goes back to the front of the retrieval order for redelivery
Dead-letterMoves the message to the dead-letter queue; you can set a reason code
Renew lockThe lock owner extends the lock (for example RenewMessageLockAsync in .NET)

Dead-letter queue (DLQ)

Subscription rules and filters

A subscription has named rules. A rule has a filter condition and optionally an action that annotates the selected message. A new subscription gets a default rule with a true filter and no action, so it receives everything until you change it.

FilterMatches onNotes
SqlFilterSQL-like condition on user and system propertiesSystem properties are prefixed with sys.
Boolean (TrueFilter, FalseFilter)Everything / nothingDerive from the SQL filter
CorrelationFilterEquality on properties such as CorrelationId, ContentType, Label, MessageId, ReplyTo, SessionId, To and user-defined propertiesSeveral properties combine with AND; string comparison is case-sensitive

Event Grid: events, topics and custom events

Custom event quickstart, in order

  1. Create a resource group.
  2. Register the Event Grid resource provider if needed: az provider register --namespace Microsoft.EventGrid.
  3. Create the custom topic: az eventgrid topic create --name $topicname -l westus2 -g gridResourceGroup.
  4. Create the message endpoint (the quickstart deploys a web app).
  5. Subscribe the endpoint with az eventgrid event-subscription create; Event Grid sends a validation event so the endpoint can confirm it wants events.
  6. Get the topic endpoint and key, then POST the event with the header aeg-sas-key.

Event Grid filters, retries and dead-lettering

Filter optionDetail
Event typesDefault: all event types of the source. Use includedEventTypes with an array, or All
Subject begins with / ends withSimple prefix or suffix on the subject; design subjects as paths (for example /A/B/C) so subscribers can filter on /A
Advanced fields and operatorsOperator type, key (number, boolean, string or array) and values; reach data fields with dot notation such as data.counter. Arrays need enableAdvancedFilteringOnArrays; arrays of objects are not supported
Retry settingRange / default
Maximum number of attempts1 to 30; default 30
Event time-to-live (TTL)1 to 1440 minutes; default 1440 minutes
Batching (off by default)Max events per batch 1 to 5,000; preferred batch size 1 to 1,024 KB; all-or-none delivery

CLI and PowerShell

TaskAzure CLIPowerShell
Register the Event Grid provideraz provider register --namespace Microsoft.EventGrid-
Create a custom topicaz eventgrid topic create --name $topicname -l westus2 -g gridResourceGroup-
Get a custom topic keyaz eventgrid topic key list --name $topicname -g gridResourceGroup --query "key1" --output tsv-
Post a custom eventcurl -X POST -H "aeg-sas-key: $key" -d "$event" $endpoint-
Send one Service Bus message-await sender.send_messages(message)
Get a Service Bus queue receiver-receiver = servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME)
Receive messages-received_msgs = await receiver.receive_messages(max_wait_time=5, max_message_count=20)
Complete a message-await receiver.complete_message(msg)

Exam Tips

Tick each tip once you can answer it without looking.

“One consumer must process each message; workers share the load” → Service Bus queue (competing consumers). Trap: A topic with subscriptions gives every subscription its own copy.

“Several back-end services each need a copy of every order message” → Topic with one subscription per service. Trap: Consumers read from subscriptions, not from the topic. A queue would split messages between them.

“A consumer crash before processing must not lose the message” → Peek lock mode, then complete. Trap: Receive and delete settles on send, so a crash loses the message.

“Message processing fails but may succeed on retry” → Abandon (or let the lock expire) so it is redelivered. Trap: Dead-letter is for messages that retrying will not fix. Delivery count rises with each abandon.

“Message keeps failing and reaches the max delivery count (default 10)” → It moves to the DLQ with reason MaxDeliveryCountExceeded. Trap: This behavior cannot be disabled; you can only raise the count.

“Read dead-lettered messages of a subscription” → <topic path>/Subscriptions/<subscription path>/$deadletterqueue. Trap: The topic has no DLQ count; the DLQ belongs to the subscription. Nothing empties the DLQ automatically.

“Messages that could not be auto-forwarded” → Transfer dead-letter queue of the source entity. Trap: They are not placed on the destination entity.

“Processing takes longer than the lock duration (default 1 minute, max 5)” → Renew the lock, or set a lock duration above normal processing time. Trap: Lock duration cannot exceed 5 minutes, so renewal is the way to go longer.

“Message was received but the receiver was closed before settling” → Settlement is lost; the lock expires and the message is redelivered (repeats lead to the DLQ). Trap: Settle before closing the receiver or client.

“Processed twice after a failed Complete” → Idempotent handler; check message-id. Trap: Peek lock is at-least-once, not exactly-once, unless you add duplicate handling or duplicate detection.

“FIFO ordered processing in a queue or subscription” → Message sessions. Trap: Queues deliver messages in order to competing consumers, but the overview names sessions as the way to realize the FIFO guarantee in processing.

“Subscription must receive only red orders; one message copy per matching rule with an action” → SQL or correlation filter rule; rules with actions each produce a copy. Trap: Rules without actions merge into one message. Filters cannot look at the message body.

“Match on CorrelationId and several properties together” → Correlation filter (properties combine with AND, string compare is case-sensitive). Trap: A SQL filter must prefix system properties with sys..

“Python: receive from a subscription” → get_subscription_receiver(topic_name=..., subscription_name=...), receive_messages, then complete_message. Trap: get_queue_receiver reads queues; get_topic_sender only sends.

“Event Grid retries a failing webhook” → Exponential backoff; max attempts 1-30 (default 30) and TTL 1-1440 minutes (default 1440); whichever expires first ends delivery. Trap: 400 and 413 responses are not retried; the event is dead-lettered if configured, otherwise dropped.

“Undelivered Event Grid events must be kept” → Configure dead-lettering with a storage account container on the event subscription. Trap: It is off by default, so the events are dropped. Writes happen five minutes after the last attempt.

“Only some Event Grid events to a subscriber” → Filter on event type, subject begins/ends with, or advanced fields (data.key with an operator). Trap: Array keys need enableAdvancedFilteringOnArrays; arrays of objects cannot be filtered.

“Publish your own application events to Event Grid” → Custom topic, event subscription, POST with aeg-sas-key. Trap: System topics are built in for Azure services. The endpoint first receives a subscription validation event.

Sources

Checked against Microsoft Learn on November 13, 2026.

← Messaging & Functions overviewAzure Functions →