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(

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine: threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration: TeamCity .NET 4.51 EF 6.0.2 VS2013 It see

Navigating Cloud Strategy after Azure Central US Region Outage

 Looking back, July 19, 2024, was challenging for customers using Microsoft Azure or Windows machines. Two major outages affected customers using CrowdStrike Falcon or Microsoft Azure computation resources in the Central US. These two outages affected many people and put many businesses on pause for a few hours or even days. The overlap of these two issues was a nightmare for travellers. In addition to blue screens in the airport terminals, they could not get additional information from the airport website, airline personnel, or the support line because they were affected by the outage in the Central US region or the CrowdStrike outage.   But what happened in reality? A faulty CrowdStrike update affected Windows computers globally, from airports and healthcare to small businesses, affecting over 8.5m computers. Even if the Falson Sensor software defect was identified and a fix deployed shortly after, the recovery took longer. In parallel with CrowdStrike, Microsoft provided a too