Skip to content

Instantly share code, notes, and snippets.

@thefringeninja
Created July 27, 2012 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefringeninja/3185489 to your computer and use it in GitHub Desktop.
Save thefringeninja/3185489 to your computer and use it in GitHub Desktop.
RabbitQueueBuilder Extension Method for Taking a URI
/*
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