Hint: Use 'az servicebus subscription create' to add subscriptions [OK]
Common Mistakes:
Using 'az servicebus topic create' for subscriptions
Using invalid 'az servicebus topic subscription create'
Incorrect command verbs or missing flags
3. Given the following code snippet, what will be the output?
from azure.servicebus import ServiceBusClient
connection_str = "Endpoint=sb://example.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=key"
topic_name = "mytopic"
subscription_name = "mysubscription"
with ServiceBusClient.from_connection_string(connection_str) as client:
receiver = client.get_subscription_receiver(topic_name, subscription_name)
with receiver:
messages = receiver.receive_messages(max_message_count=2, max_wait_time=5)
print(len(list(messages)))
medium
A. 2
B. The code will not compile
C. An exception is raised due to missing message processing
D. 0
Solution
Step 1: Understand message receiving behavior
The code tries to receive up to 2 messages with a 5-second wait. If no messages are available, it returns an empty list.
Step 2: Analyze message processing
Since no messages are explicitly sent before receiving, the list will be empty, so len(messages) is 0.
Final Answer:
0 -> Option D
Quick Check:
Receive without sent messages = 0 [OK]
Hint: Receiving messages without sending returns empty list [OK]
Common Mistakes:
Assuming messages exist without sending
Expecting exceptions for no messages
Confusing receive_messages with peek_messages
4. You have created a subscription but messages are not being received. Which of the following is the most likely cause?
medium
A. The subscription filter is set to exclude all messages
B. The topic does not exist
C. The subscription name is too long
D. The Service Bus namespace is in a different region
Solution
Step 1: Check subscription filters
If a subscription filter excludes all messages, no messages will be received even if the topic and subscription exist.
Step 2: Evaluate other options
The topic does not exist would prevent subscription creation; The subscription name is too long would cause an error; The Service Bus namespace is in a different region does not block message reception.
Final Answer:
The subscription filter is set to exclude all messages -> Option A
Quick Check:
Filter excluding messages = no messages received [OK]
Hint: Check subscription filters if no messages arrive [OK]
Common Mistakes:
Ignoring filters when troubleshooting
Assuming region mismatch blocks messages
Overlooking subscription existence
5. You want to ensure high availability and ordered message processing in your Service Bus topic subscriptions. Which configuration should you apply?
hard
A. Use multiple topics instead of subscriptions
B. Disable partitioning and use duplicate detection only
C. Enable partitioning on the topic and use sessions on subscriptions
D. Enable auto-delete on subscriptions after 1 hour
Solution
Step 1: Understand partitioning and sessions
Partitioning improves availability by spreading messages across nodes. Sessions enable ordered processing by grouping related messages.