Gotcha: Windows Azure Message Queue - 400 Bad Request
Message Queue names must not contain Illegal Characters
If you try and create a Container (like a Message Queue) in Windows Azure Storage, there is a strict naming convention to follow.
A container name must be a valid DNS name, conforming to the following naming rules:
- Container names must start with a letter or number, and can contain only letters, numbers, and the dash (-) character.
- Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not permitted in container names.
- All letters in a container name must be lowercase.
- Container names must be from 3 through 63 characters long.
Reference: Naming and Referencing Containers, Blobs, and Metadata @ MSDN
If you don't do this, you will get a 400 BAD REQUEST exception thrown, with the exception message One of the request inputs is out of range..
This is a serious gotcha. It's also a basic foundation rule of using Windows Azure, it seems.
Crap that I missed that important note when learning how to leverage Windows Azure.
Sample Code.
Take note of the two constants - one is good, one is bad.
// Good name key :)
const string QueueNameKey = "searchqueue";
// Bad name key - notice the FULL STOP in the string text?
// const string QueueNameKey = "search.queue";
// Bad name key - notice the UPPER CASE CHARACTER in the string text?
// const string QueueNameKey = "searchQueue";
// Retrieve storage account from connection string
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting(--your connection string--));
// Create the queue client
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
// Retrieve a reference to a queue
CloudQueue queue = queueClient.GetQueueReference(queueNameKey);
// Create the queue if it doesn't already exist
queue.CreateIfNotExists();
Written by Pure Krome
Related protips
3 Responses
Hey dude!
Good quote, but you said:
1st) all letter must be in lower case and then
2nd) "searchQueue" is a good name.
I double checked and it seems that it really doesn't accept uppercases.
Cheers,
Hudson
Nice pickup! Fixed :) :blush:
Thank you for posting this :)