Skip to content

Commit 0220917

Browse files
committed
Only set credentials in RabbitMQ client if needed
1 parent 0295f2e commit 0220917

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/InEngine.Core/Queuing/Clients/RabbitMQClient.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@ public class RabbitMQClient : IQueueClient, IDisposable
2323
public bool UseCompression { get; set; }
2424
IConnection _connection;
2525
public IConnection Connection { get {
26-
if (_connection == null)
27-
_connection = new ConnectionFactory() {
26+
if (_connection == null) {
27+
var factory = new ConnectionFactory() {
2828
HostName = ClientSettings.Host,
2929
Port = ClientSettings.Port,
30-
UserName = ClientSettings.Username,
31-
Password = ClientSettings.Password,
32-
AutomaticRecoveryEnabled = true
33-
}.CreateConnection();
30+
AutomaticRecoveryEnabled = true
31+
};
32+
if (!string.IsNullOrWhiteSpace(ClientSettings.Username) &&
33+
!string.IsNullOrWhiteSpace(ClientSettings.Password)) {
34+
factory.UserName = ClientSettings.Username;
35+
factory.Password = ClientSettings.Password;
36+
}
37+
38+
_connection = factory.CreateConnection();
39+
}
3440
return _connection;
3541
}
3642
}

0 commit comments

Comments
 (0)