@@ -17,14 +17,20 @@ internal sealed class DefaultRabbitMQPersistentConnection : IRabbitMQPersistentC
1717 private readonly IConnectionFactory _connectionFactory ;
1818 private readonly ILogger < DefaultRabbitMQPersistentConnection > _logger ;
1919 private IConnection _connection ;
20+ Func < string > _connectionAction ;
2021 private bool _disposed ;
2122 private readonly object sync_root = new object ( ) ;
2223
2324 public string Endpoint => _connection ? . Endpoint . ToString ( ) ;
24- public DefaultRabbitMQPersistentConnection ( RabbitMQEventBusConnectionConfiguration configuration , IConnectionFactory connectionFactory , ILogger < DefaultRabbitMQPersistentConnection > logger )
25+ public DefaultRabbitMQPersistentConnection ( RabbitMQEventBusConnectionConfiguration configuration , Func < string > connectionAction , ILogger < DefaultRabbitMQPersistentConnection > logger )
2526 {
2627 Configuration = configuration ?? throw new ArgumentNullException ( nameof ( configuration ) ) ;
27- _connectionFactory = connectionFactory ?? throw new ArgumentNullException ( nameof ( connectionFactory ) ) ;
28+ _connectionAction = connectionAction ?? throw new ArgumentNullException ( nameof ( connectionAction ) ) ;
29+ _connectionFactory = new ConnectionFactory
30+ {
31+ AutomaticRecoveryEnabled = configuration . AutomaticRecoveryEnabled ,
32+ NetworkRecoveryInterval = configuration . NetworkRecoveryInterval
33+ } ;
2834 _logger = logger ?? throw new ArgumentNullException ( nameof ( logger ) ) ;
2935 }
3036
@@ -71,6 +77,9 @@ public bool TryConnect()
7177
7278 policy . Execute ( ( ) =>
7379 {
80+ string connectionString = _connectionAction . Invoke ( ) ;
81+ _logger . WriteLog ( Configuration . Level , $ "[ConnectionString]:\t { connectionString } ") ;
82+ _connectionFactory . Uri = new Uri ( connectionString ) ;
7483 _connection = _connectionFactory . CreateConnection ( clientProvidedName : Configuration . ClientProvidedName ) ;
7584 } ) ;
7685
0 commit comments