Skip to content

Commit

Permalink
[Service Bus] Update sample for QueueProperties (#12988)
Browse files Browse the repository at this point in the history
  • Loading branch information
YijunXieMS authored Aug 10, 2020
1 parent 551fcd2 commit b5c3e7b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 40 deletions.
2 changes: 1 addition & 1 deletion sdk/servicebus/azure-servicebus/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Both [sync version](./sync_samples) and [async version](./async_samples) of samp
- Delete a queue
- Update a queue
- List queues
- Get queue description
- Get queue properties
- Get queue runtime information


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""
Example to show managing queue entities under a ServiceBus Namespace asynchronously, including
- Create a queue
- Get queue description and runtime information
- Get queue properties and runtime information
- Update a queue
- Delete a queue
- List queues under the given ServiceBus Namespace
Expand All @@ -18,7 +18,6 @@

import os
import asyncio
from azure.servicebus.management import QueueDescription
from azure.servicebus.aio.management import ServiceBusManagementClient

CONNECTION_STR = os.environ['SERVICE_BUS_CONNECTION_STR']
Expand All @@ -27,13 +26,7 @@

async def create_queue(servicebus_mgmt_client):
print("-- Create Queue")
queue_description = QueueDescription(QUEUE_NAME)
# You can adjust the settings of a queue when creating.
# Please refer to the QueueDescription class for available settings.
queue_description.max_delivery_count = 10
queue_description.dead_lettering_on_message_expiration = True

await servicebus_mgmt_client.create_queue(queue_description)
await servicebus_mgmt_client.create_queue(QUEUE_NAME, max_delivery_count=10, dead_lettering_on_message_expiration=True)
print("Queue {} is created.".format(QUEUE_NAME))
print("")

Expand All @@ -47,23 +40,23 @@ async def delete_queue(servicebus_mgmt_client):

async def list_queues(servicebus_mgmt_client):
print("-- List Queues")
async for queue_description in servicebus_mgmt_client.list_queues():
print("Queue Name:", queue_description.name)
async for queue_properties in servicebus_mgmt_client.list_queues():
print("Queue Name:", queue_properties.name)
print("")


async def get_and_update_queue(servicebus_mgmt_client):
print("-- Get and Update Queue")
queue_description = await servicebus_mgmt_client.get_queue(QUEUE_NAME)
print("Queue Name:", queue_description.name)
queue_properties = await servicebus_mgmt_client.get_queue(QUEUE_NAME)
print("Queue Name:", queue_properties.name)
print("Queue Settings:")
print("Auto Delete on Idle:", queue_description.auto_delete_on_idle)
print("Default Message Time to Live:", queue_description.default_message_time_to_live)
print("Dead Lettering on Message Expiration:", queue_description.dead_lettering_on_message_expiration)
print("Please refer to QueueDescription for complete available settings.")
print("Auto Delete on Idle:", queue_properties.auto_delete_on_idle)
print("Default Message Time to Live:", queue_properties.default_message_time_to_live)
print("Dead Lettering on Message Expiration:", queue_properties.dead_lettering_on_message_expiration)
print("Please refer to QueueProperties for complete available settings.")
print("")
queue_description.max_delivery_count = 5
await servicebus_mgmt_client.update_queue(queue_description)
queue_properties.max_delivery_count = 5
await servicebus_mgmt_client.update_queue(queue_properties)


async def get_queue_runtime_info(servicebus_mgmt_client):
Expand All @@ -73,7 +66,7 @@ async def get_queue_runtime_info(servicebus_mgmt_client):
print("Queue Runtime Info:")
print("Updated at:", queue_runtime_info.updated_at)
print("Size in Bytes:", queue_runtime_info.size_in_bytes)
print("Message Count:", queue_runtime_info.message_count)
print("Message Count:", queue_runtime_info.total_message_count)
print("Please refer to QueueRuntimeInfo from complete available runtime information.")
print("")

Expand Down
32 changes: 13 additions & 19 deletions sdk/servicebus/azure-servicebus/samples/sync_samples/mgmt_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""
Example to show managing queue entities under a ServiceBus Namespace, including
- Create a queue
- Get queue description and runtime information
- Get queue properties and runtime information
- Update a queue
- Delete a queue
- List queues under the given ServiceBus Namespace
Expand All @@ -17,21 +17,15 @@
# pylint: disable=C0111

import os
from azure.servicebus.management import ServiceBusManagementClient, QueueDescription
from azure.servicebus.management import ServiceBusManagementClient

CONNECTION_STR = os.environ['SERVICE_BUS_CONNECTION_STR']
QUEUE_NAME = "sb_mgmt_demo_queue"


def create_queue(servicebus_mgmt_client):
print("-- Create Queue")
queue_description = QueueDescription(QUEUE_NAME)
# You can adjust the settings of a queue when creating.
# Please refer to the QueueDescription class for available settings.
queue_description.max_delivery_count = 10
queue_description.dead_lettering_on_message_expiration = True

servicebus_mgmt_client.create_queue(queue_description)
servicebus_mgmt_client.create_queue(QUEUE_NAME, max_delivery_count=10, dead_lettering_on_message_expiration=True)
print("Queue {} is created.".format(QUEUE_NAME))
print("")

Expand All @@ -45,23 +39,23 @@ def delete_queue(servicebus_mgmt_client):

def list_queues(servicebus_mgmt_client):
print("-- List Queues")
for queue_description in servicebus_mgmt_client.list_queues():
print("Queue Name:", queue_description.name)
for queue_properties in servicebus_mgmt_client.list_queues():
print("Queue Name:", queue_properties.name)
print("")


def get_and_update_queue(servicebus_mgmt_client):
print("-- Get and Update Queue")
queue_description = servicebus_mgmt_client.get_queue(QUEUE_NAME)
print("Queue Name:", queue_description.name)
queue_properties = servicebus_mgmt_client.get_queue(QUEUE_NAME)
print("Queue Name:", queue_properties.name)
print("Queue Settings:")
print("Auto Delete on Idle:", queue_description.auto_delete_on_idle)
print("Default Message Time to Live:", queue_description.default_message_time_to_live)
print("Dead Lettering on Message Expiration:", queue_description.dead_lettering_on_message_expiration)
print("Auto Delete on Idle:", queue_properties.auto_delete_on_idle)
print("Default Message Time to Live:", queue_properties.default_message_time_to_live)
print("Dead Lettering on Message Expiration:", queue_properties.dead_lettering_on_message_expiration)
print("Please refer to QueueDescription for complete available settings.")
print("")
queue_description.max_delivery_count = 5
servicebus_mgmt_client.update_queue(queue_description)
queue_properties.max_delivery_count = 5
servicebus_mgmt_client.update_queue(queue_properties)


def get_queue_runtime_info(servicebus_mgmt_client):
Expand All @@ -71,7 +65,7 @@ def get_queue_runtime_info(servicebus_mgmt_client):
print("Queue Runtime Info:")
print("Updated at:", queue_runtime_info.updated_at)
print("Size in Bytes:", queue_runtime_info.size_in_bytes)
print("Message Count:", queue_runtime_info.message_count)
print("Message Count:", queue_runtime_info.total_message_count)
print("Please refer to QueueRuntimeInfo from complete available runtime information.")
print("")

Expand Down

0 comments on commit b5c3e7b

Please sign in to comment.