Example #1
0
        public void Setup()
        {
            var configService           = new AppSettingsConfigurationService();
            var connectionFactory       = new ConfiguredConnectionFactory(configService);
            var kernel                  = new StandardKernel();
            var configurationRepository = new ConfigurationRepository(connectionFactory);
            var configuration           = new QueuingConfiguration(connectionFactory, kernel, configurationRepository);

            configuration.ConfigureSystem();
        }
        public void Setup()
        {
            configurationService = new AppSettingsConfigurationService();
            connFactory          = new ConfiguredConnectionFactory(configurationService);
            var connString = connFactory.GetEddsConnection().ConnectionString;

            sqlConnection = new SqlConnection(connString);
            // TODO -- Connection string refactor
            kCura.Data.RowDataGateway.Config.SetConnectionString(connString);
            this.helper = new Mock <IHelper>();
            this.helperConnectionFactory = new HelperConnectionFactory(helper.Object);
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChannelFactory"/> class.
        /// </summary>
        /// <param name="connectionFactory">The connection factory.</param>
        public ChannelFactory(ConfiguredConnectionFactory connectionFactory)
        {
            Guard.Argument(connectionFactory, nameof(connectionFactory)).NotNull();

            ConnectionFactory = connectionFactory;
        }
Example #4
0
        /// <summary>
        /// Opens the current feed by opening all created sessions
        /// </summary>
        /// <exception cref="ObjectDisposedException"></exception>
        /// <exception cref="InvalidOperationException">
        /// The feed is already opened
        /// or
        /// The configuration is not valid
        /// </exception>
        /// <exception cref="CommunicationException">
        /// Connection to the REST-ful API failed, Probable Reason={Invalid or expired token}
        /// or
        /// Connection to the message broker failed, Probable Reason={Invalid or expired token}
        /// or
        /// </exception>
        public void Open()
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException(ToString());
            }

            try
            {
                InitFeed();

                if (Interlocked.CompareExchange(ref _opened, 1, 0) != 0)
                {
                    throw new InvalidOperationException("The feed is already opened");
                }

                _log.LogInformation($"Feed configuration: [{InternalConfig}]");

                _connectionFactory = (ConfiguredConnectionFactory)UnityContainer.Resolve <IConnectionFactory>();
                if (_connectionFactory == null)
                {
                    throw new MissingFieldException("ConnectionFactory missing.");
                }

                AttachToConnectionEvents();

                _feedRecoveryManager.ProducerUp             += MarkProducerAsUp;
                _feedRecoveryManager.ProducerDown           += MarkProducerAsDown;
                _feedRecoveryManager.CloseFeed              += OnCloseFeed;
                _feedRecoveryManager.EventRecoveryCompleted += OnEventRecoveryCompleted;

                ((ProducerManager)ProducerManager).Lock();

                ((ProducerManager)ProducerManager).RecoveryInitiated += OnRecoveryInitiated;

                foreach (var session in Sessions)
                {
                    session.Open();
                }

                var interests = Sessions.Select(s => ((OddsFeedSession)s).MessageInterest).ToList();
                _feedRecoveryManager.Open(interests);

                if (InternalConfig.StatisticsEnabled)
                {
                    _metricsTaskScheduler.Start();
                }

                _log.LogInformation("Producers:");
                foreach (var p in ProducerManager.Producers.OrderBy(o => o.Id))
                {
                    _log.LogInformation($"\tProducer {p.Id}-{p.Name.FixedLength(15)}\tIsAvailable={p.IsAvailable} \tIsEnabled={!p.IsDisabled}");
                }
            }
            catch (CommunicationException ex)
            {
                Interlocked.CompareExchange(ref _opened, 0, 1);

                // this should really almost never happen
                var result = _connectionValidator.ValidateConnection();
                if (result == ConnectionValidationResult.Success)
                {
                    throw new CommunicationException("Connection to the RESTful API failed, Probable Reason={Invalid or expired token}",
                                                     $"{InternalConfig.ApiBaseUri}:443",
                                                     ex.InnerException);
                }

                var publicIp = _connectionValidator.GetPublicIp();
                throw new CommunicationException($"Connection to the RESTful API failed. Probable Reason={result.Message}, Public IP={publicIp}",
                                                 $"{InternalConfig.ApiBaseUri}:443",
                                                 ex);
            }
            catch (BrokerUnreachableException ex)
            {
                Interlocked.CompareExchange(ref _opened, 0, 1);

                // this should really almost never happen
                var result = _connectionValidator.ValidateConnection();
                if (result == ConnectionValidationResult.Success)
                {
                    throw new CommunicationException("Connection to the message broker failed, Probable Reason={Invalid or expired token}",
                                                     $"{InternalConfig.Host}:{InternalConfig.Port}",
                                                     ex.InnerException);
                }

                var publicIp = _connectionValidator.GetPublicIp();
                throw new CommunicationException($"Connection to the message broker failed. Probable Reason={result.Message}, Public IP={publicIp}",
                                                 $"{InternalConfig.Host}:{InternalConfig.Port}",
                                                 ex);
            }
            catch (Exception)
            {
                Interlocked.CompareExchange(ref _opened, 0, 1);
                throw;
            }
        }