private void FinishedProcessing(YugiohBanlistCompletion yugiohBanlistCompletion) { _jobs.TryRemove(yugiohBanlistCompletion.Article.CorrelationId, out var job); if (yugiohBanlistCompletion.IsSuccessful) { job.SetResult(new ArticleCompletion { IsSuccessful = true, Message = yugiohBanlistCompletion.Article }); } else { var exceptionMessage = $"Card Article with id '{yugiohBanlistCompletion.Article.Id}' and correlation id {yugiohBanlistCompletion.Article.CorrelationId} not processed."; job.SetException(new Exception(exceptionMessage)); } }
public Task <YugiohBanlistCompletion> Publish(ArticleProcessed articleProcessed) { var yugiohBanlistCompletion = new YugiohBanlistCompletion(); yugiohBanlistCompletion.Article = articleProcessed.Article; yugiohBanlistCompletion.Banlist = articleProcessed.Banlist; try { var messageBodyBytes = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(articleProcessed.Banlist)); var factory = new ConnectionFactory() { HostName = _rabbitMqConfig.Value.Host }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { var props = channel.CreateBasicProperties(); props.ContentType = _rabbitMqConfig.Value.ContentType; props.DeliveryMode = _rabbitMqConfig.Value.Exchanges[RabbitMqExchangeConstants.YugiohHeadersData].PersistentMode; props.Headers = _rabbitMqConfig.Value.Exchanges[RabbitMqExchangeConstants.YugiohHeadersData].Headers.ToDictionary(k => k.Key, k => (object)k.Value); channel.BasicPublish ( RabbitMqExchangeConstants.YugiohHeadersData, "", props, messageBodyBytes ); } yugiohBanlistCompletion.IsSuccessful = true; } catch (Exception ex) { Console.WriteLine(ex); throw; } return(Task.FromResult(yugiohBanlistCompletion)); }