What is Service Bus's equivalent to MSMQ's CanRead?

112 Views Asked by At

I am converting an application which used MSMQ to use an interface with adapters than can handle either MSMQ or Service Bus (either on-prem or Azure versions) queues. One of the application's usages of MSMQ was a configuration inspector feature to determine that the system has proper privileges to perform certain actions. It uses System.Messaging.MessageQueue.CanRead to verify that we can successfully read a given queue that is important to the application (it was a frequent security misconfiguration by customers).

The best equivalent in Service Bus is not apparent to me. My first thought on an approach would be to attempt to QueueClient.Peek() and catch any ensuing exceptions. The Peek method does not offer a timeout parameter, so I can only hope that this will happen quickly. I would prefer to use a timeout so I can force it to return quickly in the likely scenario that there are currently no messages to read. There is Receive(TimeSpan serverWaitTime) where I can pass in a tiny wait time, but I think that would require me to use a transaction and abort it if I do happen to receive a message. That would lock up the queue when I would rather prefer not to.

I'm hoping there's a better option I have missed.

1

There are 1 best solutions below

0
On BEST ANSWER

When you create a MessageReceiver, you need to specify the connection string of the namespace + sas key. If you provide a sas key that does not allow read permission on the queue, you ll get an exception.