0
0
Azurecloud~10 mins

Service Bus topics and subscriptions in Azure - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Service Bus topic using Azure CLI.

Azure
az servicebus topic create --resource-group myResourceGroup --namespace-name myNamespace --name [1]
Drag options to blanks, or click blank then click option'
AmySubscription
BmyQueue
CmyTopic
DmyNamespace
Attempts:
3 left
💡 Hint
Common Mistakes
Using subscription or namespace names instead of the topic name.
Confusing topic with queue names.
2fill in blank
medium

Complete the code to create a subscription for a Service Bus topic.

Azure
az servicebus topic subscription create --resource-group myResourceGroup --namespace-name myNamespace --topic-name myTopic --name [1]
Drag options to blanks, or click blank then click option'
AmySubscription
BmyQueue
CmyTopic
DmyNamespace
Attempts:
3 left
💡 Hint
Common Mistakes
Using topic or namespace names instead of subscription name.
Confusing subscription with queue or topic names.
3fill in blank
hard

Fix the error in the code to send a message to a Service Bus topic using Azure SDK for Python.

Azure
from azure.servicebus import ServiceBusClient, ServiceBusMessage

connection_str = 'Endpoint=sb://myNamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=key'

with ServiceBusClient.from_connection_string(connection_str) as client:
    sender = client.get_topic_sender(topic_name=[1])
    message = ServiceBusMessage('Hello World')
    sender.send_messages(message)
Drag options to blanks, or click blank then click option'
A'mySubscription'
B'myTopic'
C'myQueue'
D'myNamespace'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing subscription or queue names instead of topic name.
Not using quotes around the topic name string.
4fill in blank
hard

Fill both blanks to create a subscription with a filter rule to only receive messages with label 'important'.

Azure
az servicebus topic subscription rule create --resource-group myResourceGroup --namespace-name myNamespace --topic-name myTopic --subscription-name mySubscription --name [1] --filter-sql-expression [2]
Drag options to blanks, or click blank then click option'
AImportantRule
B'sys.Label = ''important'''
C'sys.Label = important'
DDefaultRule
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect quotes in the filter expression.
Using default rule name when a custom name is expected.
5fill in blank
hard

Fill all three blanks to receive messages from a subscription using Azure SDK for Python and complete the message processing.

Azure
from azure.servicebus import ServiceBusClient

connection_str = 'Endpoint=sb://myNamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=key'

with ServiceBusClient.from_connection_string(connection_str) as client:
    receiver = client.get_subscription_receiver(topic_name=[1], subscription_name=[2])
    with receiver:
        messages = receiver.receive_messages(max_message_count=1, max_wait_time=5)
        for msg in messages:
            print(msg.body.decode())
            receiver.[3](msg)
Drag options to blanks, or click blank then click option'
A'myTopic'
B'mySubscription'
Ccomplete_message
Dabandon_message
Attempts:
3 left
💡 Hint
Common Mistakes
Using queue or namespace names instead of topic or subscription names.
Calling wrong method to complete message processing.