Search code examples
c#rabbitmqconnection-stringapplication-settings

How to secure RabbitMQ connection string for EasyNetQ and c#?


I need to read the connection string from the config file but I dont like the idea of saving the password in clear

RabbitHutch.CreateBus("host=MYHOST;username=MYUSER;password=MYPWD", sr => sr.Register<IEasyNetQLogger>(_ => new RabbitMQLogger()))

What would it be a best practice? The question is not just about how to secure strings/settings but also how to secure RabbitMQ connection details.


Solution

  • I probably found the answer

    public static IBus CreateMessageBus()
    {
        var connectionString = ConfigurationManager.ConnectionStrings["easynetq"];
        if (connectionString == null || connectionString.ConnectionString == string.Empty)
        {
            throw new VaultServiceException("easynetq connection string is missing or empty");
        }
    
        return RabbitHutch.CreateBus(connectionString.ConnectionString);
    }