Created
July 27, 2012 00:48
-
-
Save thefringeninja/3185489 to your computer and use it in GitHub Desktop.
RabbitQueueBuilder Extension Method for Taking a URI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
AppHarbor/CloudAMQP supplies the CloudAMQP RabbitMQ info as a Uri in AppSettings; | |
this adds support for that. | |
most of this code is from the rabbitmq-dotnet-client. | |
*/ | |
public static class RabbitExtensions | |
{ | |
private static string UriDecode(string uri) | |
{ | |
return Uri.UnescapeDataString(uri.Replace("+", "%2B")); | |
} | |
public static RabbitQueueBuilder<T> AtEndpoint<T>(this RabbitQueueBuilder<T> builder, Uri uri) | |
{ | |
var userInfo = uri.UserInfo; | |
if (false == String.IsNullOrEmpty(userInfo)) | |
{ | |
var userPass = userInfo.Split(':'); | |
if (userPass.Length > 2) | |
{ | |
throw new ArgumentException("Bad user info in AMQP " + | |
"URI: " + userInfo); | |
} | |
builder.UserName = UriDecode(userPass[0]); | |
if (userPass.Length == 2) | |
{ | |
builder.Password = UriDecode(userPass[1]); | |
} | |
} | |
return builder.ToHost(uri.Host) | |
//.OnVirtualHost(uri.AbsolutePath) | |
.OnPort(uri.Port); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment