Complete the code to create a Service Bus topic using Azure CLI.
az servicebus topic create --resource-group myResourceGroup --namespace-name myNamespace --name [1]The topic name is required to create a Service Bus topic. Here, myTopic is the correct name for the topic.
Complete the code to create a subscription for a Service Bus topic.
az servicebus topic subscription create --resource-group myResourceGroup --namespace-name myNamespace --topic-name myTopic --name [1]The subscription name is required to create a subscription under a topic. Here, mySubscription is the correct subscription name.
Fix the error in the code to send a message to a Service Bus topic using Azure SDK for Python.
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)
The get_topic_sender method requires the topic name as a string. Here, 'myTopic' is the correct topic name to send messages to.
Fill both blanks to create a subscription with a filter rule to only receive messages with label 'important'.
az servicebus topic subscription rule create --resource-group myResourceGroup --namespace-name myNamespace --topic-name myTopic --subscription-name mySubscription --name [1] --filter-sql-expression [2]
The rule name can be any valid string, here ImportantRule is used. The filter expression must be a valid SQL expression as a string, so 'sys.Label = ''important''' is correct with proper quotes.
Fill all three blanks to receive messages from a subscription using Azure SDK for Python and complete the message processing.
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)
The get_subscription_receiver method requires the topic and subscription names as strings. After processing, complete_message is called to mark the message as processed.