private void Initialize(object state) { // NOTE: Called from a ThreadPool thread _logger.LogInformation(String.Format("SQL message bus initializing, TableCount={0}", _configuration.TableCount)); while (true) { try { var installer = new SqlInstaller(_connectionString, _tableNamePrefix, _configuration.TableCount, _logger); installer.Install(); break; } catch (Exception ex) { // Exception while installing for (var i = 0; i < _configuration.TableCount; i++) { OnError(i, ex); } _logger.LogError("Error trying to install SQL server objects, trying again in 2 seconds: {0}", ex); // Try again in a little bit Thread.Sleep(2000); } } for (var i = 0; i < _configuration.TableCount; i++) { var streamIndex = i; var tableName = String.Format(CultureInfo.InvariantCulture, "{0}_{1}", _tableNamePrefix, streamIndex); var stream = new SqlStream(streamIndex, _connectionString, tableName, _logger, _dbProviderFactory); stream.Queried += () => Open(streamIndex); stream.Faulted += (ex) => OnError(streamIndex, ex); stream.Received += (id, messages) => OnReceived(streamIndex, id, messages); _streams.Add(stream); StartReceiving(streamIndex); } }
private void Initialize(object state) { // NOTE: Called from a ThreadPool thread while (true) { try { var installer = new SqlInstaller(_connectionString, _tableNamePrefix, _configuration.TableCount, _trace); installer.Install(); break; } catch (Exception ex) { // Exception while installing for (var i = 0; i < _configuration.TableCount; i++) { OnError(i, ex); } // Try again in a little bit Thread.Sleep(2000); } } for (var i = 0; i < _configuration.TableCount; i++) { var streamIndex = i; var stream = new SqlStream(streamIndex, _connectionString, tableName: String.Format(CultureInfo.InvariantCulture, "{0}_{1}", _tableNamePrefix, streamIndex), open: () => Open(streamIndex), onReceived: OnReceived, onError: ex => OnError(streamIndex, ex), traceSource: _trace, dbProviderFactory: _dbProviderFactory); _streams.Add(stream); StartStream(streamIndex); } }