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.
0 comments:
Post a Comment