Skip to content

Commit fca27b2

Browse files
committed
(pardahlman#132) Move connect to virtual method
So that it can be overriden, error handled etc by custom implementations
1 parent 9c49460 commit fca27b2

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/RawRabbit/Channel/ChannelFactory.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,28 @@ public class ChannelFactory : IChannelFactory
2828
private bool _processingRequests;
2929

3030
public ChannelFactory(IConnectionFactory connectionFactory, RawRabbitConfiguration config, ChannelFactoryConfiguration channelConfig)
31+
{
32+
ConnectToBroker();
33+
_connectionFactory = connectionFactory;
34+
_config = config;
35+
_channelConfig = channelConfig;
36+
_requestQueue = new ConcurrentQueue<TaskCompletionSource<IModel>>();
37+
_channels = new LinkedList<IModel>();
38+
39+
Initialize();
40+
}
41+
42+
protected virtual void ConnectToBroker()
3143
{
3244
try
3345
{
34-
_connection = connectionFactory.CreateConnection(config.Hostnames);
46+
_connection = _connectionFactory.CreateConnection(_config.Hostnames);
3547
}
3648
catch (BrokerUnreachableException e)
3749
{
3850
_logger.LogError("Unable to connect to broker", e);
3951
throw e.InnerException;
4052
}
41-
_connectionFactory = connectionFactory;
42-
_config = config;
43-
_channelConfig = channelConfig;
44-
_requestQueue = new ConcurrentQueue<TaskCompletionSource<IModel>>();
45-
_channels = new LinkedList<IModel>();
46-
47-
Initialize();
4853
}
4954

5055
internal virtual void Initialize()

0 commit comments

Comments
 (0)