private async Task PublishToSubscribers(MarketEventModel marketEvent)
        {
            var subscribers = await GetSubscribers();

            var publishTasks = subscribers.Select(url => PublishToSubscriber(url, marketEvent));
            await Task.WhenAll(publishTasks);
        }
Beispiel #2
0
 private async Task PublishToSubscriber(SubscriberModel subscriber, MarketEventModel model)
 {
     using (var client = _httpClientFactory.CreateClient())
     {
         await client.PostAsync(subscriber.Url, new JsonContent <MarketEventModel>(model));
     }
 }
 private async Task PublishToSubscriber(string url, MarketEventModel marketEventModel)
 {
     using (var client = _httpClientFactory.CreateClient(HttpClientName))
     {
         try
         {
             client.Timeout = TimeSpan.FromSeconds(1);
             await client.PostAsJsonAsync(url, marketEventModel);
         }
         catch (Exception e)
         {
             _logger.LogWarning("Failed to publish event to {subscriber}\r\n {exception}", url, e);
         }
     }
 }
 public void AddMarketEvent(MarketEventModel marketEvent)
 {
     _marketEvents.Add(marketEvent);
 }
Beispiel #5
0
 public async Task SendQuote(MarketEventModel model)
 {
     await _hubContext.Clients.All.SendAsync("ReceiveQuote", model.PayloadAs <QuoteModel>());
 }
        public async Task Publish <T>(T model, MarketEventType?marketEventType = null)
        {
            var marketEvent = new MarketEventModel(model, marketEventType);

            await PublishToSubscribers(marketEvent);
        }
Beispiel #7
0
        public async Task <IActionResult> IncomingEvents([FromBody] MarketEventModel model)
        {
            await _quotesService.SendQuote(model);

            return(Ok());
        }
Beispiel #8
0
 public async Task PublishQuote(QuoteModel model)
 {
     var marketEvent = new MarketEventModel(model);
     var tasks       = _subscribers.Select(s => PublishToSubscriber(s, marketEvent));
     await Task.WhenAll(tasks);
 }
Beispiel #9
0
 public IActionResult Incoming([FromBody] MarketEventModel marketEvent)
 {
     _subscriber.AddMarketEvent(marketEvent);
     return(Accepted());
 }