Skip to main content

How to iterage a Service Bus Queue using Azure SDK 2.0 & What are the concerns of this new feature

The new version of Windows Azure Service Bus came with a lot of new feature. One of the new feature that was added in Windows Azure SDK 2.0 is the support of message browsing.
What is message browsing? This is a functionality that gives the ability to a client to iterate and access messages from a Service Bus Queue without locking or removing a message from the actual queue.
There are pretty interesting thing that we can do using this feature. For example we can peek a message from a specific index in the queue:
BrokenMessage message = queueClient.Peek(3);
Or we can peek the first message that is available:
BrokenMessage message = queueClient.Peek();
Another option is to peek a specific number of message from the queue:
IEnumerable<BrokenMessage> messages = queueClient.PeekBatch(20);
The PeekBatch support also two parameters, where the first one is used to specify the starting index (similar with Peek(3)):
IEnumerable<BrokenMessage> messages = queueClient.PeekBatch(100, 20)
In the above example we peek the next 20 messages, starting from the index 100.
Interesting feature, from now one we can iterate a queue. Great! But I have an open question:
Why would we want to iterate a queue?
If we need a functionality like this, then maybe we don’t use the proper service. For example, we would say that we need this feature when we need to do monitoring or audit of a system. Well… true – we could use this feature to have audit system over a queue, BUT. Yes, there is a big BUT. Why would you use a queue when you need to support audit over it. You can use Service Bus Topic and have a dedicated subscription for the audit system. For the same price, you can have a system that was created for this scenario.
Other cases when people would find this feature useful would be in the moment when they need to debug the application. They could see the content of the queue – the investigation process would be easier. True, I had the “opportunity” to   debug a system that use queues and when you cannot control the content of the queue, then the nightmare begin. When problem like this occurs I would try to use the death letter feature – when a message cannot be processed X times, than the message is send automatically to death letter queue.
I see the value of this feature when we need to make debug or to investigate the content of a queue. In the same time this feature can open Pandora’s door. Why? Because developer will use this feature in strange way and from a queue we will end up with a list.

Comments

  1. Thanks for great posts on service bus. Can you please advise me how to use Topic and subscription in the below scenario?

    There are multiple senders and multiple receivers. one message sent by sender needs to be received by all the receivers. After the last receiver reads the message , the message should be deleted. The receivers may be switched off at different times for maintenance.

    How can we identify that a particular message has been received by other modules so that it can be deleted?

    Thanks in advance

    ReplyDelete
  2. Thanks for the post. I am currently trying to use PeekBatch. It works...sort-of. The first time it returns my only message in the queue, but it won't work again for five minutes. My guess is that PeekBatch is actually locking the messages, which seems like a bug if that is true. Have you successfully got PeekBatch to work back-to-back before? I just posted this on StackOverflow, so hopefully I'm just missing something here. http://stackoverflow.com/questions/18520714/azure-service-bus-queue-peekbatch-locking

    ReplyDelete
    Replies
    1. PeekBatch extract the messages from the queue. The message will not be available anymore in the queue - the message is deleted.
      If you don't have messages anymore in the queue, than the PeekBatch will freeze until new messages are available or the timeout time will expire.
      If you need to get messages from the queue without deleting them than you need to use another method that will make receive and lock ReceiveBatch - http://msdn.microsoft.com/en-us/library/windowsazure/jj673067.aspx

      Delete

Post a Comment

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(...

How to audit an Azure Cosmos DB

In this post, we will talk about how we can audit an Azure Cosmos DB database. Before jumping into the problem let us define the business requirement: As an Administrator I want to be able to audit all changes that were done to specific collection inside my Azure Cosmos DB. The requirement is simple, but can be a little tricky to implement fully. First of all when you are using Azure Cosmos DB or any other storage solution there are 99% odds that you’ll have more than one system that writes data to it. This means that you have or not have control on the systems that are doing any create/update/delete operations. Solution 1: Diagnostic Logs Cosmos DB allows us activate diagnostics logs and stream the output a storage account for achieving to other systems like Event Hub or Log Analytics. This would allow us to have information related to who, when, what, response code and how the access operation to our Cosmos DB was done. Beside this there is a field that specifies what was th...

Cloud Myths: Cloud is Cheaper (Pill 1 of 5 / Cloud Pills)

Cloud Myths: Cloud is Cheaper (Pill 1 of 5 / Cloud Pills) The idea that moving to the cloud reduces the costs is a common misconception. The cloud infrastructure provides flexibility, scalability, and better CAPEX, but it does not guarantee lower costs without proper optimisation and management of the cloud services and infrastructure. Idle and unused resources, overprovisioning, oversize databases, and unnecessary data transfer can increase running costs. The regional pricing mode, multi-cloud complexity, and cost variety add extra complexity to the cost function. Cloud adoption without a cost governance strategy can result in unexpected expenses. Improper usage, combined with a pay-as-you-go model, can result in a nightmare for business stakeholders who cannot track and manage the monthly costs. Cloud-native services such as AI services, managed databases, and analytics platforms are powerful, provide out-of-the-shelve capabilities, and increase business agility and innovation. H...