Skip to content

Commit

Permalink
[ServiceBus] update migration guide with message count info (#20360)
Browse files Browse the repository at this point in the history
  • Loading branch information
swathipil authored and iscai-msft committed Sep 29, 2021
1 parent d7ae308 commit eca17a6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
17 changes: 14 additions & 3 deletions sdk/servicebus/azure-servicebus/migration_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,8 @@ In V7 of this library, we simplified this as below:

### Working with Administration Client

In v0.50, you could create/get/update/delete/list Service Bus queues/topics/subscriptions/rules using the `control_client`.
In v7, this is replaced by the `ServiceBusAdministrationClient`.
The following code snippets show how to manage queues, similar methods are provided on the `ServiceBusAdministrationClient` to manage topics, subscriptions and rules.
In v0.50, you could create/get/update/delete/list Service Bus queues/topics/subscriptions/rules using the `control_client`. You were also able to retrieve associated metadata, like `message_count`.
In v7, this is replaced by the `ServiceBusAdministrationClient`. The property `total_message_count` on `QueueRuntimeProperties` has now replaced `message_count` on `Queue`. More specific properties about message counts - `active_message_count`, `scheduled_message_count` and `dead_letter_message_count` - are also available. Similar methods are provided on the `ServiceBusAdministrationClient` to manage topics, subscriptions and rules. The following code snippets show how to manage queues and retrieve associated metadata.

In V0.50:
```python
Expand All @@ -374,6 +373,10 @@ queue = service_bus_service.get_queue(queue_name)
service_bus_service.create_queue(queue_name)
service_bus_service.delete_queue(queue_name)
queues = service_bus_service.list_queues()

# get message count info
for queue in queues:
print(queue.message_count)
```

In V7:
Expand All @@ -384,6 +387,14 @@ queue = service_bus_administration_client.get_queue(queue_name)
service_bus_administration_client.create_queue(queue_name)
service_bus_administration_client.delete_queue(queue_name)
queues = service_bus_administration_client.list_queues()

# get total, active, scheduled, dead-letter message count info
for queue in queues:
queue_runtime_properties = service_bus_administration_client.get_queue_runtime_properties(queue.name)
print(queue_runtime_properties.total_message_count)
print(queue_runtime_properties.active_message_count)
print(queue_runtime_properties.scheduled_message_count)
print(queue_runtime_properties.dead_letter_message_count)
```

### Migration samples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ async def get_queue_runtime_properties(servicebus_mgmt_client):
print("Updated at:", queue_runtime_properties.updated_at_utc)
print("Size in Bytes:", queue_runtime_properties.size_in_bytes)
print("Message Count:", queue_runtime_properties.total_message_count)
print("Active Message Count:", queue_runtime_properties.active_message_count)
print("Scheduled Message Count:", queue_runtime_properties.scheduled_message_count)
print("Dead-letter Message Count:", queue_runtime_properties.dead_letter_message_count)
print("Please refer to QueueRuntimeProperties from complete available runtime properties.")
print("")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ def get_and_update_queue(servicebus_mgmt_client):

def get_queue_runtime_properties(servicebus_mgmt_client):
print("-- Get Queue Runtime Properties")
get_queue_runtime_properties = servicebus_mgmt_client.get_queue_runtime_properties(QUEUE_NAME)
print("Queue Name:", get_queue_runtime_properties.name)
queue_runtime_properties = servicebus_mgmt_client.get_queue_runtime_properties(QUEUE_NAME)
print("Queue Name:", queue_runtime_properties.name)
print("Queue Runtime Properties:")
print("Updated at:", get_queue_runtime_properties.updated_at_utc)
print("Size in Bytes:", get_queue_runtime_properties.size_in_bytes)
print("Message Count:", get_queue_runtime_properties.total_message_count)
print("Updated at:", queue_runtime_properties.updated_at_utc)
print("Size in Bytes:", queue_runtime_properties.size_in_bytes)
print("Message Count:", queue_runtime_properties.total_message_count)
print("Active Message Count:", queue_runtime_properties.active_message_count)
print("Scheduled Message Count:", queue_runtime_properties.scheduled_message_count)
print("Dead-letter Message Count:", queue_runtime_properties.dead_letter_message_count)
print("Please refer to QueueRuntimeProperties from complete available runtime properties.")
print("")

Expand Down

0 comments on commit eca17a6

Please sign in to comment.