public void Run() { _logger.WriteInfoAsync("Broker.Run", null, "Starting broker"); try { _rabbitMqService.Subscribe <ExternalExchangeOrderbookMessage>(_settings.Nested(s => s.RabbitMq.Consumers.FiatOrderbooks), false, _orderbookAggregatorService.ProcessNewExternalOrderbookAsync); _rabbitMqService.Subscribe <ExternalExchangeOrderbookMessage>(_settings.Nested(s => s.RabbitMq.Consumers.CryptoOrderbooks), false, _orderbookAggregatorService.ProcessNewExternalOrderbookAsync); } catch (Exception ex) { _logger.WriteErrorAsync("Broker.Run", null, ex); } }
public async Task StartApplicationAsync() { _consoleWriter.WriteLine($"Starting {ServiceName}"); await _logger.WriteInfoAsync(ServiceName, null, null, "Starting..."); try { await _migrationService.InvokeAll(); _rabbitMqService.Subscribe( _marginSettings.MarketMakerRabbitMqSettings, false, HandleNewOrdersMessage, _rabbitMqService.GetJsonDeserializer <MarketMakerOrderCommandsBatchMessage>()); if (_marginSettings.RisksRabbitMqSettings != null) { _rabbitMqService.Subscribe(_marginSettings.RisksRabbitMqSettings, true, _matchingEngineRoutesManager.HandleRiskManagerCommand, _rabbitMqService.GetJsonDeserializer <MatchingEngineRouteRisksCommand>()); } else if (_marginSettings.IsLive) { _logger.WriteWarning(ServiceName, nameof(StartApplicationAsync), "RisksRabbitMqSettings is not configured"); } // Demo server works only in MM mode if (_marginSettings.IsLive) { _rabbitMqService.Subscribe(_marginSettings.StpAggregatorRabbitMqSettings .RequiredNotNull(nameof(_marginSettings.StpAggregatorRabbitMqSettings)), false, HandleStpOrderbook, _rabbitMqService.GetMsgPackDeserializer <ExternalExchangeOrderbookMessage>()); } var settingsCalcTime = (_marginSettings.OvernightSwapCalculationTime.Hours, _marginSettings.OvernightSwapCalculationTime.Minutes); var registry = new Registry(); registry.Schedule <OvernightSwapJob>().ToRunEvery(0).Days().At(settingsCalcTime.Hours, settingsCalcTime.Minutes); JobManager.Initialize(registry); JobManager.JobException += info => _logger.WriteError(ServiceName, nameof(JobManager), info.Exception); } catch (Exception ex) { _consoleWriter.WriteLine($"{ServiceName} error: {ex.Message}"); await _logger.WriteErrorAsync(ServiceName, "Application.RunAsync", null, ex); } }
private static void Subscribe <TMessage>(IRabbitMqService rabbitMqService, string connectionString, string exchangeName, Func <TMessage, Task> handler) { var settings = new RabbitMqSettings { ConnectionString = connectionString, ExchangeName = exchangeName, }; rabbitMqService.Subscribe(settings, false, handler, rabbitMqService.GetJsonDeserializer <TMessage>()); }
public void Start() { _rabbitMqService.Subscribe( _dataReaderSettings.Consumers.MarginTradingEnabledChanged, false, m => { _marginTradingSettingsCacheService.OnMarginTradingEnabledChanged(m); return(Task.CompletedTask); }, _rabbitMqService.GetJsonDeserializer <MarginTradingEnabledChangedMessage>()); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { await Task.Run(() => { _rabbitMqService.Subscribe <CommentMessageNotity>(ea => { var key = "user:connection:1"; var connectionId = new CsRedisBase().Get(key); _hubContext.Clients.Client(connectionId).SendAsync("Test", ea); Console.WriteLine(JsonConvert.SerializeObject(ea)); }); }); }
public async Task StartApplicationAsync() { _consoleWriter.WriteLine($"Starting {ServiceName}"); await _logger.WriteInfoAsync(ServiceName, null, null, "Starting..."); if (_marginSettings.MarketMakerRabbitMqSettings == null && _marginSettings.StpAggregatorRabbitMqSettings == null) { throw new Exception("Both MM and STP connections are not configured. Can not start service."); } try { await _migrationService.InvokeAll(); if (_marginSettings.MarketMakerRabbitMqSettings != null) { _rabbitMqService.Subscribe( _marginSettings.MarketMakerRabbitMqSettings, false, HandleNewOrdersMessage, _rabbitMqService.GetJsonDeserializer <MarketMakerOrderCommandsBatchMessage>()); } else { _logger.WriteInfo(ServiceName, nameof(StartApplicationAsync), "MarketMakerRabbitMqSettings is not configured"); } if (_marginSettings.FxRateRabbitMqSettings != null) { _rabbitMqService.Subscribe(_marginSettings.FxRateRabbitMqSettings, false, _fxRateCacheService.SetQuote, _rabbitMqService.GetMsgPackDeserializer <ExternalExchangeOrderbookMessage>()); } if (_marginSettings.StpAggregatorRabbitMqSettings != null) { _rabbitMqService.Subscribe(_marginSettings.StpAggregatorRabbitMqSettings, false, HandleStpOrderbook, _rabbitMqService.GetMsgPackDeserializer <ExternalExchangeOrderbookMessage>()); } else { _logger.WriteInfo(ServiceName, nameof(StartApplicationAsync), "StpAggregatorRabbitMqSettings is not configured"); } if (_marginSettings.RisksRabbitMqSettings != null) { _rabbitMqService.Subscribe(_marginSettings.RisksRabbitMqSettings, true, _matchingEngineRoutesManager.HandleRiskManagerCommand, _rabbitMqService.GetJsonDeserializer <MatchingEngineRouteRisksCommand>()); } else { _logger.WriteInfo(ServiceName, nameof(StartApplicationAsync), "RisksRabbitMqSettings is not configured"); } var settingsChanged = new RabbitMqSettings { ConnectionString = _marginSettings.MtRabbitMqConnString, ExchangeName = _marginSettings.RabbitMqQueues.SettingsChanged.ExchangeName }; _rabbitMqService.Subscribe(settingsChanged, true, HandleChangeSettingsMessage, _rabbitMqService.GetJsonDeserializer <SettingsChangedEvent>()); } catch (Exception ex) { _consoleWriter.WriteLine($"{ServiceName} error: {ex.Message}"); await _logger.WriteErrorAsync(ServiceName, "Application.RunAsync", null, ex); } }
public void StartConsume() { _rabbitMqService.Subscribe <DailyTaskDTO>(ea => { _dailyTaskJob.AddJob(ea); }); }