1

I need an example on how to make CRUD operations on service bus queues.

I actually need an instance of Microsoft.Azure.Management.ServiceBus.SBQueue class, so I can count the messages in that queue.

2
  • Please provide us with some (relevant) code and additional information like what you tried and why that didn't work. SO is not a one-stop-code-shop. In its current form, this question is no fit for SO. Please refer to How to Ask. On-topic: Get message counters Commented Oct 25, 2021 at 10:02
  • "...so I can count the messages in that queue". Why do you want to do that? You generally want to avoid doing such things with messaging systems based due to the way messaging apps work in the first place Commented Oct 25, 2021 at 10:11

2 Answers 2

5

The older way is to use the ManagementClient

var managementClient = new ManagementClient(connectionString);
var queueRuntimeInfo = await managementClient.GetQueueRuntimeInfoAsync(queueName);
Console.WriteLine(queueRuntimeInfo.MessageCount);

The more modern way is to use ServiceBusAdministrationClient

var client = new ServiceBusAdministrationClient(connectionString);
var runtimeProperties = await client.GetQueueRuntimePropertiesAsync(queueName);
Console.WriteLine(runtimeProperties .ActiveMessageCount);
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your answer but this is the legacy way. The current way is with ServiceBusManagementClient but I cannot instantiate it
any idea how to filter by message Session ID?
2

Use ServiceBusAdministrationClient()

var client = new ServiceBusAdministrationClient(_connectionString);
QueueRuntimeProperties queue = await client.GetQueueRuntimePropertiesAsync(queueName);
int count = (int)queue.ActiveMessageCount;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.