Passing URI to RabbitMQ

17,048

Solution 1

Apparently, there is no way to encode or escape the @ character in password. I changed password for the user to avoid this character and everything worked as expected.

Solution 2

you can try this:-

 string rabbitmqconnection = $"amqp://{HttpUtility.UrlEncode("username")}: 
 {HttpUtility.UrlEncode("password")}@{"hostname"}
 /{HttpUtility.UrlEncode("/vhost")}";

hope this will resolve your problem.

Solution 3

You need to URLEncode to the symbol @ in the password.

According to your situation, you can try this uri:

amqp://userid:mypass%4025@myrabbitserver:5672/filestream
Share:
17,048
techspider
Author by

techspider

I am a regular .Net and SQL developer

Updated on June 04, 2022

Comments

  • techspider
    techspider almost 2 years

    I am connecting to RabbitMQ using below code

    factory.UserName = "userid";
    factory.Password = "mypass@25";
    factory.VirtualHost = "/filestream";
    factory.Port = AmqpTcpEndpoint.UseDefaultPort;
    factory.HostName = "myrabbitserver";
    return factory.CreateConnection();
    

    I wanted to change connection settings to the below format:

    amqp://userid:mypass@25@myrabbitserver:5672/filestream
    

    My password has @ character due to which I'm not able to pass URI

    var factory = new ConnectionFactory();
    factory.Uri = "amqp://userid:mypass@25@myrabbitserver:5672/filestream";
    

    I end up supplying each attribute of factory manually. Is there a way that we can tell RabbitMQ that my password has @ by doing something like below?

    factory.Uri = "amqp://userid:"mypass@25"@myrabbitserver:5672/filestream";
    

    If I try to change @ in the password to %40, it throws an error when acquiring the connection

    None of the specified endpoints were reachable
    
  • techspider
    techspider about 8 years
    i'm trying from App.config only; I pasted here for easy reference for others; your syntax ins config is still using @server/vhost; do you mean I remove /vhost?
  • jhilden
    jhilden about 8 years
    a vhost (virtual host) is a concept in rabbit to separate different queues for different users. If you don't need it, you can omit it. Also, my code works great from both web.config or app.config
  • techspider
    techspider about 8 years
    do you have @ symbol in your password?
  • jhilden
    jhilden about 8 years
    no, the @ symbol is the separator between the password and the name of the server
  • techspider
    techspider about 8 years
    yes, I have @ in my password too; that's causing the confusion for RabbitMQ
  • teo van kot
    teo van kot over 7 years
    What do you mean by "why"?