Message Queue – What’s In A Name?

One things I am constantly falling into the trap of doing is naming my message queues using camel casing when naming my queues giving names such as “mySuperQueue” which ends up throwing the below error. Which because it gives us very little information tends to lead to me debugging the code for a while before I remember that capitals and other special characters are not allowed in queue names.

Dominic Green - queueError The rules on naming queue are:

A queue name must start with a letter or number, and may contain only letters, numbers, and the dash (-) character.

The first and last letters in the queue name must be alphanumeric. The dash (-) character may not be the first or last letter.

All letters in a queue name must be lowercase.

A queue name must be from 3 through 63 characters long.

So to try and stop myself making this mistake in the future I have put together a quick code snippet that allows me to pass in the proposed queue name and view if it is valid.

            bool match = false;
            var exp = new Regex(@"^[0-9a-z]+-*[0-9a-z]+$");

            if (exp.IsMatch(input))
            {
                if (input.Length >= 3 && input.Length <= 63)
                {
                    match = true;
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("VALID Queue Name: {0}", input);
                }
            }

            if (!match)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("INVALID Queue Name: {0}", input);
            }

 

Dominic Green - QueueNames

Hopefully this small snippet will be able to save me a lot of time by instantly flagging a queue name that is invalid, then either notifying the user before the queues are created or even fixing the queue name so that it is in a correct format.

This entry was posted on Friday, January 8th, 2010 at 12:58 and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply