Skip to content

Commit 8ed8df2

Browse files
committed
provide vhost and port as configuration option
1 parent 9155462 commit 8ed8df2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/ServiceCollectionExtensions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,25 @@ public static IServiceCollection AddRabbitMqEventBus(this IServiceCollection ser
1313
});
1414

1515
public static IServiceCollection RegisterRabbitMqConnection(this IServiceCollection services, ILogger logger, string hostName,
16-
string userName, string password, int retryCount = 5)
16+
string userName, string password, string vHost = null, int port = 5672, int retryCount = 5)
1717
{
1818
return services.AddSingleton<IRabbitMQPersistentConnection>(_ =>
1919
{
2020
var factory = new ConnectionFactory
2121
{
2222
HostName = hostName,
23-
DispatchConsumersAsync = true
23+
DispatchConsumersAsync = true,
24+
Port = port
2425
};
2526

2627
if (!string.IsNullOrWhiteSpace(userName))
2728
factory.UserName = userName;
2829

2930
if (!string.IsNullOrWhiteSpace(password))
3031
factory.Password = password;
32+
33+
if (!string.IsNullOrWhiteSpace(vHost))
34+
factory.VirtualHost = vHost;
3135

3236
return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount);
3337
});

0 commit comments

Comments
 (0)