how to add virtual host when creating .Net Aspire RabbitMQ Container?

187 Views Asked by At

How to add virtual host when creating .Net Aspire RabbitMQ Container?

var RabbitMQ = builder.AddRabbitMQContainer("messagingRabbitMQ");

Code I'm using to connect from the client apps.

var connection = registrationContext.GetRequiredService<IConnection>();

configurator.Host(new Uri($"amqp://{connection.Endpoint.HostName}:{connection.Endpoint.Port}"),
    rabbitMqConfiguration.VirtualHost, host =>
    {
        host.Username(rabbitMqConfiguration.Username);
        host.Password(DefaultSettings.Instance.RabbitMqPassword);
    });
1

There are 1 best solutions below

3
TechGuy On

If you want to specify a virtual host for RabbitMQ, you usually include it as part of the connection string when setting up your RabbitMQ client.

Here's an example of how you might configure RabbitMQ in a .NET application with a virtual host:

services.AddRabbitMQ(options =>
{
    options.HostName = "your-rabbitmq-host";
    options.Port = 5672; // Default RabbitMQ port
    options.VirtualHost = "your-virtual-host";
    options.UserName = "your-username";
    options.Password = "your-password";
});