In the previous post in this series I’ve discussed some of the foundational principles of the new Queue and Router features of the .NET Services Bus and the role that policies play in turning names in the namespace into messaging primitives. In this post I’ll start drilling into the capabilities of the Queue feature and will discuss what’s in the queue policy.
The capabilities of the Queue are best explored by looking at the Queue policy. Policies can be expressed in two ways: You can either you use the .NET Services SDK’s Microsoft.ServiceBus.QueuePolicy class with a .NET application or you can just whip up a bit of XML. The structure and the serialized representation of that class is exactly equivalent to an XML queue policy you’d wire up “by hand” and thus I’ll discuss the policy in terms of its XML elements:
The queue policy has the element name “QueuePolicy” within the XML namespace “http://schemas.microsoft.com/ws/2007/08/connect”. That’s the namespace we use for most protocols and data structures in the .NET Service Bus at this development stage and you should expect that we’re migrating to the “final” V1 namespaces in one of the next CTPs. If you use the .NET class you’ll just have to recompile to snap to new namespaces once they come around.
Below is a list of the policy’s elements and the permitted values. All elements are optional and can appear at most once. The default value applies when an element is omitted. It’s perfectly ok to send an empty QueuePolicy and accept the default values to keep things simple. I’d recommend to always set the ExpirationInstant value, however.
One required forward reference: Don’t get confused or distracted trying to figure out from here what it means “to provide an authorization token”. The docs explain this and I’ll also address this in the next blog post when I dive into the protocol.
Phew! Lots of options. The good thing is that most apps should be ok with the defaults.
I know that the 2MB capacity limit is somewhat disappointing and I’m certainly not happy with it. There’s a particular behavior (with bug number) that may occur under very rare circumstances in the underlying replication system, which caused us to play it very safe instead of risking data loss. I don’t think the limit is a showstopper for apps that send notifications and events around – it is a showstopper for apps that want to exchange larger payloads and we’re working to relax that limit and make Queues much, much larger as soon as we can. You can obviously always spool larger data into SDS or one of the Azure storage systems and then send a reference to that data as a message, but it’d be strange for a messaging system to make that a required pattern for data of all sizes. If we’re talking hundreds of megabytes it makes sense, though.
With the due apology out of the way, let’s look at how a policy may be applied to a namespace name – or in other words, how a queue is created in the simplest case (this must be done via HTTPS). The model here is that the client proposes a policy and Service Bus is at liberty to adjust the policy.
If you are intimately familiar with Atom, you’ll notice that the <QueuePolicy> is an extension and isn’t carried as <content>. That’s by intent. <content> is for people, extensions are for apps. We’ll start using <content> in a later milestone, so consider that being reserved.
HTTP/1.1 POST /myapp/q1Host: clemensv.servicebus.windows.netX-MS-Identity-Token: A6hbJklu18hsnHRql61k1==Content-Type: application/atom+xml;type=entry;charset=utf-8Content-Length: nnn<entry xmlns=”http://www.w3.org/2005/Atom”> <QueuePolicy xmlns=”http://schemas.microsoft.com/ws/2007/08/connect”> <ExpirationInstant>2009-04-03T12:00:00</ExpirationInstant> </QueuePolicy> </entry>
If the queue can be created, the response is a 200 and you get the policy back along with any adjustments that the service may make. This is called the “effective” policy, i.e. that’s what the server is using. You also learn about where you can modify the policy, since – as I explained before – the endpoint where you POST the policy to is morphing into the Queue’s tail.
HTTP/1.1 200 OKLocation: https://project-name.servicebus.windows.net/myapp/q1!(queue)Content-Type: application/atom+xml;type=entry;charset=utf-8Content-Length: nnn<entry xmlns=”http://www.w3.org/2005/Atom”> <link rel=”self” href=”https://project-name.servicebus.windows.net/myapp/q1!(queue)” /> <link rel=”alternate” href=”https://project-name.servicebus.windows.net/myapp/q1” /> <link rel=”queuehead” href=”https://project-name.servicebus.windows.net/myapp/q1!(queue/head)” /> <QueuePolicy xmlns=”http://schemas.microsoft.com/ws/2007/08/connect” > <ExpirationInstant>2009-04-03T12:00:00</ExpirationInstant> <MaxQueueCapacity>2097152</MaxQueueCapacity> </QueuePolicy></entry>
If you want to renew the Queue (extend the expiration), take the effective policy, adjust ExpirationInstant and do a PUT to the “self” location.
HTTP/1.1 PUT /myapp/q1!(queue)Host: project-name.servicebus.windows.netX-MS-Identity-Token: A6hbJklu18hsnHRql61k1==Content-Type: application/atom+xml;type=entry;charset=utf-8Content-Length: nnn<entry xmlns=”http://www.w3.org/2005/Atom”> <link rel=”self” href=”https://project-name.servicebus.windows.net/myapp/q1!(queue)” /> <link rel=”alternate” href=”https://project-name.servicebus.windows.net/myapp/q1” /> <link rel=”queuehead” href=”https://project-name.servicebus.windows.net/myapp/q1!(queue/head)” /> <QueuePolicy xmlns=”http://schemas.microsoft.com/ws/2007/08/connect” > <ExpirationInstant>2009-04-04T12:00:00</ExpirationInstant> <MaxQueueCapacity>2097152</MaxQueueCapacity> </QueuePolicy></entry>
[Bug note: The PUT will return the new effective policy just like the POST response shown above, but the returned Atom <links> aren’t correctly formed. Keep the ones returned from the POST]
If you want to delete the queue, just nuke the policy:
HTTP/1.1 DELETE /myapp/q1!(queue)Host: project-name.servicebus.windows.netX-MS-Identity-Token: A6hbJklu18hsnHRql61k1==Content-Length: 0
So that’s the policy story for Queues. In the next posts I’ll discuss the REST Queue protocol and the SOAP Queue protocol for how you send message to the queue and get messages out. REST I’ll explain in protocol terms, the SOAP model in .NET programming model terms.