/// <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}]"); _connection = UnityContainer.Resolve <IConnectionFactory>().CreateConnection(); _connection.ConnectionShutdown += OnConnectionShutdown; _connection.CallbackException += OnCallbackException; _feedRecoveryManager.ProducerUp += MarkProducerAsUp; _feedRecoveryManager.ProducerDown += MarkProducerAsDown; _feedRecoveryManager.CloseFeed += OnCloseFeed; _feedRecoveryManager.EventRecoveryCompleted += OnEventRecoveryCompleted; ((ProducerManager)ProducerManager).Lock(); foreach (var session in Sessions) { session.Open(); } var interests = Sessions.Select(s => ((OddsFeedSession)s).MessageInterest).ToList(); _feedRecoveryManager.Open(interests); if (InternalConfig.StatisticsEnabled) { _metricsTaskScheduler.Start(); } } 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; } }
public void PublicIpIsRetrieved() { var publicIp = _validator.GetPublicIp(); Assert.IsNotNull(publicIp); }
public void PublicIpIsRetrieved() { _validator.GetPublicIp(); }
/// <summary> /// Opens the current feed /// </summary> /// <exception cref="ObjectDisposedException">The feed is already disposed</exception> /// <exception cref="InvalidOperationException">The feed is already opened</exception> /// <exception cref="CommunicationException"> Connection to the message broker failed, Probable Reason={Invalid or expired token}</exception> public void Open() { if (_isDisposed) { throw new ObjectDisposedException(ToString()); } if (Interlocked.CompareExchange(ref _isOpened, 1, 0) != 0) { throw new InvalidOperationException("The feed is already opened"); } try { _rabbitMqMessageReceiverForTickets.MqMessageReceived += OnMqMessageReceived; //_rabbitMqMessageReceiverForTickets.MqMessageDeserializationFailed += OnMqMessageDeserializationFailed; _rabbitMqMessageReceiverForTickets.Open(); _rabbitMqMessageReceiverForTicketCancels.MqMessageReceived += OnMqMessageReceived; //_rabbitMqMessageReceiverForTicketCancels.MqMessageDeserializationFailed += OnMqMessageDeserializationFailed; _rabbitMqMessageReceiverForTicketCancels.Open(); _rabbitMqMessageReceiverForTicketCashouts.MqMessageReceived += OnMqMessageReceived; //_rabbitMqMessageReceiverForTicketCashouts.MqMessageDeserializationFailed += OnMqMessageDeserializationFailed; _rabbitMqMessageReceiverForTicketCashouts.Open(); _rabbitMqMessageReceiverForTicketNonSrSettle.MqMessageReceived += OnMqMessageReceived; //_rabbitMqMessageReceiverForTicketNonSrSettle.MqMessageDeserializationFailed += OnMqMessageDeserializationFailed; _rabbitMqMessageReceiverForTicketNonSrSettle.Open(); _ticketPublisherFactory.Open(); if (_config.StatisticsEnabled) { _metricsTaskScheduler.Start(); } } catch (CommunicationException ex) { // this should really almost never happen var result = _connectionValidator.ValidateConnection(); if (result == ConnectionValidationResult.Success) { throw new CommunicationException( "Connection to the API failed, Probable Reason={Invalid or expired token}", $"{_config.Host}:{_config.Port}", ex.InnerException); } var publicIp = _connectionValidator.GetPublicIp(); throw new CommunicationException( $"Connection to the API failed. Probable Reason={result.Message}, Public IP={publicIp}", $"{_config.Host}:{_config.Port}", ex); } catch (BrokerUnreachableException ex) { // 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}", $"{_config.Host}:{_config.Port}", ex.InnerException); } var publicIp = _connectionValidator.GetPublicIp(); throw new CommunicationException( $"Connection to the message broker failed. Probable Reason={result.Message}, Public IP={publicIp}", $"{_config.Host}:{_config.Port}", ex); } _executionLog.LogInformation("MtsSdk instance opened."); }
/// <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 { if (Interlocked.CompareExchange(ref _opened, 1, 0) != 0) { throw new InvalidOperationException("The feed is already opened"); } InitFeed(); _log.Info($"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); _log.Info("Producers:"); foreach (var p in ProducerManager.Producers.OrderBy(o => o.Id)) { _log.Info($"\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; } }