IList<string> QueueInsert(IList<Book> entities) { ////foreach (var entity in entities) ////{ //// QueueInsert(entity); ////} _productCatalogMongoRepository.SetDocumentDefaults<Book>(entities); var searchDocs = new List<BookSearchDocument>(); var task = _queueClient.Bus.RequestAsync<IList<Book>, BooksQueueResponse>(entities); task.ContinueWith(response => { foreach (var entity in response.Result.Books) { var searchDoc = new BookSearchDocument { Id = entity.Id, Title = entity.Name, Author = new MXSearchDenormalizedRefrence { DenormalizedId = entity.Author.DenormalizedId, DenormalizedName = entity.Author.DenormalizedName }, Category = new MXSearchDenormalizedRefrence { DenormalizedId = entity.Category.DenormalizedId, DenormalizedName = entity.Category.DenormalizedName }, AvaliableCopies = entity.AvaliableCopies, }; searchDocs.Add(searchDoc); } _queueClient.Bus.Publish<IList<BookSearchDocument>>(searchDocs); }); return entities.Select(c => c.Id).ToList(); }
//Storing book information and then flowing it to search engine is absolutely critical to me. Hence queuing this to RabbitMQ string QueueInsert(Book entity) { _productCatalogMongoRepository.SetDocumentDefaults(entity); //getting the mongoEntityID first, then queue to Search engine. RPC based queuing var task = _queueClient.Bus.RequestAsync<IMXEntity, BookQueueResponse>(entity); task.ContinueWith(response => { var searchDoc = new BookSearchDocument { Id = response.Result.Id, Title = entity.Name, Author = new MXSearchDenormalizedRefrence { DenormalizedId = entity.Author.DenormalizedId, DenormalizedName = entity.Author.DenormalizedName }, Category = new MXSearchDenormalizedRefrence { DenormalizedId = entity.Category.DenormalizedId, DenormalizedName = entity.Category.DenormalizedName }, AvaliableCopies = entity.AvaliableCopies, }; _queueClient.Bus.Publish<ISearchDocument>(searchDoc); }); return "queued"; }