[This post series is based on preview features that are subject to change]
This is an epilogue of my 3-part blog series on the recently released Service Bus preview features.
part 3: Shared Access Authorization
Why an epilogue?
I’ve missed another feature in the preview library – message browse, which allows you to iterate through the messages without blocking any receivers. But, before I get to that, I have to clarify one thing regarding what I said in the Message Pump post. When you call Client.Receive() method, you can specify a timeout of any duration to wait for a message to arrive. This is not a long-polling, but it does allow you to specify a timeout period before the method returns. So, the price comparison in the original post isn’t that relevant after all. However, the gist of that post is never about price reduction, but about how Message Pump enables event-driven programming model, which is really natural to client applications, especially rich clients. With that said, let’s move on to the main topic: Message Browse.
Message Browse
Message browse can be useful in scenarios where you need to provide monitoring or tracing capabilities without affecting existing clients. For example, you can examine top 10 messages from dead-lettered queue. Or, you can provide live monitoring of pending jobs (such as if a job related to a specific customer has appeared on the queue). Here I’ll just present a very simple Console application as an example:
static void Main(string[] args) { var conString = "[SB Connection String]"; var queueName = "workqueue"; QueueClient sender = QueueClient.CreateFromConnectionString(conString, queueName); for (int i = 0; i < 10; i++) sender.Send(new BrokeredMessage(string.Format("Message {0}", i+1))); QueueClient receiver = QueueClient.CreateFromConnectionString(conString, queueName, ReceiveMode.ReceiveAndDelete); BrokeredMessage message = null; do { message = receiver.Peek(); if (message != null) Console.WriteLine("Message found: " + message.GetBody<string>()); } while (message != null); Console.ReadLine(); message = null; do { message = receiver.Receive(); if (message != null) Console.WriteLine("Message received: " + message.GetBody<string>()); } while (message != null); Console.ReadLine(); }
The above code sends 10 messages to a queue, browses the messages by using the Peek() method (highlighted yellow), and then retrieves the messages using the Receive() method (highlighted green). Because the Peek() method doesn’t remove any messages from the queue, Recevie() calls are not affected afterwards and all the messages can be received.
Send us your feedbacks!
I hope you’ve learned some useful information from this blog series. And I know the production team is eager to hear from you. Are the features useful in your scenarios? What are we missing? Where do we need to improve? The whole idea of the preview library is to get your feedbacks so that we can make the final product better. So, if you have any feedbacks, either positive or negative, please don’t hesitate to send them my way, and I’ll make sure they are heard by the team. You can either leave comments to this blog, or send tweets to @HaishiBai2010. Thank you for reading!
Add a comment