protected void EnsurePublishChannelIsCreated() { if (!IsOpened) { // NOTE: Due to the implementation of IsOpened (DurableConnection.IsConnected), the _dedicatedPublishingChannel could be null because the RabbitMQ connection is possibly establised by a different instance of RabbitTunnel _connection.Connect(); } // NOTE: After connect, the _dedicatedPublishingChannel will be created synchronously. // If for above reason, this channel has not been created, we can create it here if (_dedicatedPublishingChannel == null || !_dedicatedPublishingChannel.IsOpen) { CreatePublishChannel(); } }
protected void EnsurePublishChannelIsCreated() { if (!IsOpened) { // NOTE: Due to the implementation of IsOpened, the _dedicatedPublishingChannel could be null because the connection is establised by different instance of RabbitTunnel _connection.Connect(); } // NOTE: After connect, the _dedicatedPublishingChannel will be created synchronously. // If for above reason, this channel has not been created, we can create it here if (_dedicatedPublishingChannel == null || !_dedicatedPublishingChannel.IsOpen) { CreatePublishChannel(); // If still failed, it's time to throw exception if (_dedicatedPublishingChannel == null || !_dedicatedPublishingChannel.IsOpen) { throw new Exception("No channel to rabbit server established."); } } }
private IDurableConnection CreateConnection() { lock (_syncObj) { if (_connection == null || !_connection.IsConnected) { var clusterConnections = _connectionString.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); var factories = clusterConnections.Select(x => new ManagedConnectionFactory(new ConnectionString(x))).ToList(); _connection = new HaConnection(new DefaultRetryPolicy(), Global.DefaultWatcher, factories); _connection.Connect(); } return(_connection); } }