Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Service Bus] Update sample for QueueProperties #12988

Merged
merged 2 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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